Verified and Tested 02/04/2021
Introduction
In this How-To, we will walk you through the installation of a LAMP stack on a CentOS 7 based server. Although we are writing this article in the context of CentOS 7, a Linux, Apache, MariaDB, PHP(LAMP) server is a common installation stack capable of being hosted on many different Operating Systems. Examples of such are Debian (see our how-to on this here) and Debian based distributions like Ubuntu (see our how-to for Ubuntu here), or RHEL and RHEL based distributions such as Fedora or Scientific Linux. You’ll see these installations occurring on a variety of hosting platforms such as shared web hosting, dedicated hosting and cloud hosting.
In the case of this article, we’ll be utilizing the YUM package manager associated with the RHEL distribution CentOS.
Prerequisites
A server with CentOS 7 installed will take care of the Linux aspect of the LAMP stack install. If you do not have a server, consider a reliable SSD virtual private server from Atlantic.Net.
Installing Apache on CentOS 7
Install Apache with the following command to begin the install:
sudo yum install httpd
Start Apache with the following command:
sudo systemctl start httpd
We can now verify Apache is working by opening your browser and entering the URL http://your-server's-address
. you should get a blue Apache 2 test page similar to the image below.
Note: If you do not know your IP address, run the following command:
ip addr show eth0An example of running the command: ip addr show eth0 and getting 192.168.100.10 for the IP address.In our example we would put
http://192.168.100.10
into our browser’s address bar.
Apache 2 Test page
Installing MariaDB on CentOS 7
Install MariaDB with the following command to begin the install:
sudo yum install mariadb-server
Start the service with the following command
sudo systemctl start mariadb
Set root MySQL password with the following command:
/usr/bin/mysql_secure_installation
Note: You will be prompted with a series of questions. Simply type Y for yes on all of them, see the screenshot below:
Sample mysql_secure_installation
Installing PHP on CentOS 7
First, you will need to install EPEL and Remi repository in your system. You can install it with the following command:
sudo yum install epel-release sudo yum install http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
Next, Install PHP with the following command to begin the install:
sudo yum --enablerepo=remi-php74 install php php-mysql
Create a test PHP file in the following directory with the following command:
sudo vi /var/www/html/info.php
Insert the following code in the empty space then save and exit:
<?php phpinfo(); ?>
Restart apache so all the changes take effect:
sudo systemctl restart httpd
Test your page in your browser with the following hyperlink changed with your IP address:
http://YOUR.IP.ADD.RESS/info.php
It is a good idea to remove your php.info file as it can be used to aid an attacker to compromise your server. You can do that with the following command:
sudo rm /var/www/html/info.php
If you would like Apache and MariaDB to start on boot, run the following commands:
sudo systemctl enable httpd
sudo systemctl enable mariadb
Congratulations! You have just installed a LAMP stack on your CentOS 7 Server. Thank you for following along in this How-To and check back with us for any new updates, or to learn more about our industry-leading VPS hosting solutions.