Atlantic.Net Blog

How to Install a LAMP (Apache, MariaDB, PHP) stack on CentOS 7

LAMP Magic In Your Hands created by Walker Cahall

Verified and Tested 02/04/2021


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.


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 eth0
An example of running the command: ip addr show eth0 and getting for the IP address.

In our example we would put 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:


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

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:


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:

php apache

It is a good idea to remove your 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.

Get started with 12 months of free cloud VPS hosting

Free Tier includes:
G3.2GB Cloud VPS Server Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year