Install Apache, MySQL and PHP on CentOS 7 Servers
This guide is available in template form to deploy to VPS Servers running Virtuozzo. Rebuild your server from the client area or the VPS control panel using this image – CentOS-7-86_x64-Apache-MySQL-PHP. Install Apache MySQL PHP.
We have already covered how to install Apache, MySQL and PHP on a CentOS 6 system so now we are going to go through the steps on how to install Apache, MySQL and PHP on a CentOS 7 system. We are going to use a LAMP stack to install the required software to an NVMe VPS Server.
Users should be using a SUDO user on servers. If you have not created a SUDO user you should do this first.
Install Apache – CentOS 7 Server
*If you are using one of our templates on your VPS Apache is installed by default.
sudo yum install httpd
Once Apache is installed, start Apache
sudo systemctl start httpd.service
At this point, you should be able to visit your servers IP address and see the default Apache webpage.
HINT: If you do not know your servers IP address you can use curl to curl the icanhazip.com website to return your IP address.
Providing you can see the default Apache webpage above next, you will want to start Apache on reboots. We do this with the following command
sudo systemctl enable httpd.service
Install MySQL (MariaDB) On CentOS 7
Now you have Apache working you will next want to install MySQL issue the below commands to get started
sudo yum install mariadb-server mariadb
Once the installation is complete next, start MySQL
sudo systemctl start mariadb
Finally, we will run the MySQL secure script. This will ask you to enter a password. Since this is a new install leave this blank and press enter to continue then, create a new MySQL root password. Answer y for the rest of the questions.
Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorization. New password: password Re-enter new password: password Password updated successfully! Reloading privilege tables.. ... Success!
The last thing to do is to start MySQL on reboots with the following command
sudo systemctl enable mariadb.service
Install PHP on CentOS 7
Now you have Apache and MySQL setup and working the final thing to do is install PHP. We will be using yum again to install PHP to your server. To start, issue the below command
sudo yum install php php-mysql
PHP should now be installed. You will need to restart Apache to have them both work together. Issue the below command
sudo systemctl restart httpd.service
Install PHP Modules
The very last thing to do is install any PHP modules you require. To do this you can request a full list of modules available with the below command
sudo yum search php-
The returned result will look like this
php-bcmath.x86_64 : A module for PHP applications for using the bcmath library php-cli.x86_64 : Command-line interface for PHP php-common.x86_64 : Common files for PHP php-dba.x86_64 : A database abstraction layer module for PHP applications php-devel.x86_64 : Files needed for building PHP extensions php-embedded.x86_64 : PHP library for embedding in applications php-enchant.x86_64 : Enchant spelling extension for PHP applications php-fpm.x86_64 : PHP FastCGI Process Manager php-gd.x86_64 : A module for PHP applications for using the gd graphics library
To get more information about each extension you can use the yum info function. For example;
sudo yum info php-enchant
To install individual modules you can use
sudo yum install package
To install multiple modules you can use
sudo yum install package1 package2 package3
* Just switch package for the required module like this
sudo yum install php-enchant php-fpm php-cli
Final Testing Of PHP (Optional)
At this point, your server is now set up with Apache, MySQL and PHP. you can continue testing your software to ensure all is working fine. We can create a PHP file with the default phpinfo script inside the file then, call that file via a browser which will display all the default PHP values on the server. If you have configured everything correctly this file will display. If something is wrong it will not display.
The file needs to be placed in the servers web root folder. On CentOS systems this is /var/www/html/ so, let’s use nano to create a info.php file and enter the default php code
Inside this file place the following code
<?php phpinfo(); ?>
Save and exit the file. You should now navigate to http://YOUR_IP/info.php to see if the file renders. If it does your all good to go. If it does not before you retrace the steps in this guide try allowing HTTP and HTTPS traffic through the firewall. Issue the below commands
sudo firewall-cmd --permanent --zone=public --add-service=http sudo firewall-cmd --permanent --zone=public --add-service=https sudo firewall-cmd --reload
After you have finished testing your server you will want to remove this file so just issue the below command
sudo rm /var/www/html/info.php
Install PHP 7.3 on CentOS 7
This template is also available for First2Host customers to use. You can reinstall using this template from your client area or the VPS control panel.
To Install PHP 7 just run the below commands
yum remove php* yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
Video Tutorial – Install Apache, MySQL and PHP
How Was This Article – Install Apache MySQL PHP
You might also like
More from All About Linux
How to install FTP and configure FTP on an Ubuntu 22 LTS instance
If you need to upload files to your NVMe VPS you have a couple of options. You can use a …
How to install a Cloudflare Origin SSL Certificate – NGINX
An SSL Certificate is vital to encrypt data between you and your clients. SSLs can be complicated things. If they …
How To Open Port FirewallD and Close Port FirewallD -CentOS 7
Open And Close Ports In FirewallD - Manage Zones In FirewallD Like IPtables, FirewallD is a Linux firewall that filters packets …