Installing Apache, MySQL, and PHP on a CentOS Cloud Server
A historical 2021 walkthrough for building an Apache, MySQL, and PHP environment on CentOS 7 or 8 with yum-based packages.
Contents6 sections
Historical note: This article records a CentOS 7/8 setup from May 2021. Several repositories and package versions are now obsolete. Treat the commands as an archived learning reference, verify current vendor documentation, and use strong unique credentials on any real server.
- Linux used in the original setup: CentOS 8.2
- Package manager: yum / dnf
Installing Apache
The Apache package is named httpd on CentOS 7 and 8:
yum install httpd
systemctl start httpd
Confirm the installation by opening the server's public address in a browser. If the Apache page does not appear, check whether another service already occupies port 80. Apache configuration lives under /etc/httpd, including conf/httpd.conf.
The default document root is:
/var/www/html
Upload the site's files there, for example with WinSCP. Apache serves index.html as the default page.
Installing MySQL on CentOS 8
Install the repository package, update package metadata, and install the server:
rpm -ivh mysql-community-release-el8-1.noarch.rpm
yum update
yum install mysql-server
systemctl start mysqld.service
Log in with:
mysql -u root -p
The original article used this SQL only as a simple example:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'replace-with-a-strong-password';
During secure installation, MySQL asks whether to:
- remove anonymous users;
- disallow remote root login;
- remove the test database and access to it;
- reload privilege tables.
For a production system, removing anonymous users and the test database, reloading privileges, and keeping remote root login disabled are the safer defaults. Create a separate least-privileged user for remote application access.
Installing MySQL on CentOS 7
The archived CentOS 7 sequence was:
rpm -Uvh https://repo.mysql.com/mysql57-community-release-el7-11.noarch.rpm
yum --enablerepo=mysql80-community install mysql-community-server
systemctl start mysqld.service
CentOS 7 installations commonly generated a temporary password. Retrieve it with:
grep "A temporary password" /var/log/mysqld.log
Then run:
mysql_secure_installation
mysql -u root -p
Remote database connections
The original setup checked connectivity with a desktop MySQL client. A successful connection confirms that the server, user grants, firewall, and cloud security-group rules line up.
Do not expose the MySQL port broadly to the internet. Restrict access to known addresses, prefer a VPN or SSH tunnel, and never enable remote root login merely for convenience.
Installing PHP on CentOS 8
The 2021 setup added EPEL and Remi repositories:
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
rpm -Uvh http://rpms.remirepo.net/enterprise/remi-release-8.rpm
dnf -y install dnf-utils
yum search php74\*
yum install php74-php
The original service commands were:
service php-fpm start
service php-fpm stop
service php-fpm restart
ps -A | grep -i php
To test PHP integration, create /var/www/html/index.php:
<?php phpinfo(); ?>
Open the server address and confirm that PHP renders the information page. Remove this diagnostic file afterward because it exposes environment details.
Installing PHP on CentOS 7
The archived CentOS 7 sequence used Webtatic packages:
rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum list php\*
yum install php72w-fpm php72w-mysql php72w-mysqli php72w php72w-opcache php72w-gd php72w-intl php72w-mbstring php72w-exif php72w-mcrypt php72w-openssl
systemctl restart httpd
At that point the original learning environment had Apache, MySQL, and PHP connected. For a current deployment, replace these end-of-life distributions and packages with supported releases before following an equivalent setup.
Related posts
Discussion / approved
Comments
No comments yet.