Search Our Database

Install LAMP on CentOS 7

Last updated on |

LAMP is an acronym for Linux, Apache, MySQL, and PHP. It is needed to run web servers due to it containing various software required for other web content management software, such as WordPress and also Joomla.

Linux = Choice of operating system, ie: Red Hat, CentOS, Ubuntu.

Apache = Web server application.

MySQL = World’s second most widely used relational database management system (RDBMS).

PHP = Server-side scripting language designed for web development and general-purpose programming language.


Step 1: Install Apache

1) Run the following command to install Apache onto your system:

yum install httpd

2) Then run this line to start Apache service on your system:

systemctl start httpd.service

3) Before checking whether Apache is running, we need to disable the firewall. In CentOS 7, iptables is replaced by firewalld. Use the following command to turn it off:

systemctl stop firewalld.service

4) Finally, open your browser and type in your server’s IP into the URL, the page below should appear.


5) Now we enable Apache to start on boot using the command:

systemctl enable httpd.service

Step 2: Install MySQL (MariaDB)

CentOS 7’s repository comes packaged with MariaDB instead of MySQL by default, thus we use MariaDB in place of MySQL

1) Run the following command to install MariaDB onto your system:

yum install mariadb-server mariadb

2) Then, type the following commands to start and enable MariaDB on boot:

systemctl start mariadb.service
systemctl enable mariadb.service

3) After that, we add in some security measures to our database using the following command:


Since we just installed MariaDB there shouldn’t be a root password, press enter then select if you want to add in a password for MariaDB root account. After that, simply enter “y” for the rest of the prompts.


4) Now access MariaDB by logging in as root using the following command:

mysql -u root -p

Enter the password you have just set (if any) and press Enter.


Now you can perform various actions on your database, but we will not discuss that here. Type “exit” and Enter to exit MariaDB.


Step 3: Install PHP

1) Now install PHP onto our system using the command:

yum install php php-mysql

2) Restart Apache

systemctl restart httpd.service

3) Now we create a file named info.php to that will show various information on the PHP installation. Type the following command in terminal:

 vi /var/www/html/info.php

Then, copy the block of text below it into the newly created file:


Save and exit. Then in your browser, type “<your-server-ip>/info.php” into your URL. The loaded page should look like this:


With that, LAMP is now successfully installed on your system.