Today, let us learn how to install LAMP stack on your CentOS 7. For starters, the LAMP represents Linux, Apache, MySQL, and PHP.
In this tutorial, we will cover the steps needed to install a LAMP stack on your CentOs 7, and if you have challenges on your first CentOS Virtual Machine, check this tutorial below:
Install a CentOS 7 Minimal Server in Virtual Machine with screenshots
First, let us update your CentOS by the command below:
yum update
You should have the same output below:

Once completed, let us install Apache (LAMP), run the command below:
yum install httpd

Make sure to enter y for you to proceed, and you should have the same output below:

Next, we need to start Apache service by running the command below:
systemctl start httpd
At this point, you can check httpd service running as expected by using the command below:
systemctl status httpd
You should have the same output below:

What is Apache?
is a free and open-source cross-platform web server, released under the terms of Apache License 2.0.
Next, you need to activate Apache to start during system boot using the command below:
systemctl enable httpd

Before we can use the httpd service, let us add this service to firewall-cmd first. To do so, run the command below:
firewall-cmd --permanent --add-service=http
To apply consistency iptables rules on firewall use –permanent option and restart firewalld service to take effect.
systemctl restart firewalld
Other important Firewalld options are presented below:
firewall-cmd --state
firewall-cmd --list-all
firewall-cmd --list-interfaces
firewall-cmd --get-service
firewall-cmd --query-service service_name
firewall-cmd --add-port=8080/tcp
What is firewall-cmd?
is the command line client of the firewalld daemon. It provides interface to manage runtime and permanent configuration.
From here you should be all set. You can test your work by accessing your Virtual Machine IP address on your browser.

Next service will be MySQL. CentOS 7.0 switched from MySQL to MariaDB for its default database management system.
To install MariaDB database use the following command.
yum install mariadb-server mariadb
You should have the same output below:

After MariaDB package is installed, start database daemon and use mysql_secure_installation script to secure database.
systemctl start mariadb
mysql_secure_installation
Since you just installed MySQL, you most likely won’t have one, so leave it blank by pressing enter.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Then the prompt will ask you if you want to set a root password. Go ahead and choose Y and follow the instructions.

CentOS automates the process of setting up MySQL, asking you a series of yes or no questions.
It’s easiest just to say Yes to all the options and by the end, MySQL will reload and implement the new changes.
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y
... Success!
By default, MySQL comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
Once completed, ensure MariaDB will start during boot, you can run the command below:
systemctl enable mariadb
What is MariaDB?
is one of the most popular database servers in the world. It’s made by the original developers of MySQL and guaranteed to stay open source.
At this point, you should have a working Apache, and MariaDB. Let us proceed in installing PHP for us to complete our LAMP Stack tutorial.
The PHP version that ships with CentOS as default is quite old (PHP 5.4). Therefore I will show you in this chapter some options to install newer PHP versions like PHP 7.0 or 7.1 from Remi repository.
Add the Remi CentOS repository.
rpm -Uvh http://rpms.remirepo.net/enterprise/remi-release-7.rpm

Install yum-utils as we need the yum-config-manager utility.
yum -y install yum-utils

and run yum update
yum update
Now you have to choose which PHP version you want to use on the server and if you wish to use PHP 5.4, here are the command below:
yum -y install php
To install PHP 7.0 and the Apache PHP 7.0 module as follows:
yum-config-manager --enable remi-php70

yum -y install php php-opcache

For PHP 7.1, here are the command below:
yum-config-manager --enable remi-php71
yum -y install php php-opcache
In our situation, I used PHP 7.0 for this tutorial. On the other hand, for you to get the PHP version installed on your machine, run the command below.
php --version

At this point, you should be all set. Great job.