How to install LAMP in cent os 7

LAMP stands for linux, Apache HTTP server, MySQL/MariaDB database and PHP/Perl/Python

We are going to learn to install LAMP in centos -7

I am going to set my hostname as and as its ip address.

Steps to install Apache

Apache is an open-source web server. It is widely used as it has vairous features including SSL CGI and virtual domains.

Execute the commands below to install apache

yum install httpd -y

We will need to start the apache service on every boot and we can do this by executing the commands given below:

systemctl start httpd

systemctl enable httpd


Ensure to check the firewall or router if your server is behind these. make sure they are remotely accessible.


systemctl restart firewalld

We can simply test apache navigation to httpd://localhost or http://server-ip-address/.


Installing MariaDB

We have a replacement for MYSQL in centos 7 which is scalable and reliable.

Execute the command below to install it

yum install mariadb-server mariadb -y

Similarly to start on every boot

systemctl start mariadb

systemctl enable mariadb

We will need to set password for the mysql as by default it is empty.

For the security reason lets change the default root password

/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found


In order to log into MariaDB to secure it, we’ll need the current
password for the root user. If you’ve just installed MariaDB, and
you haven’t set the root password yet, the password will be blank,
so you should just press enter here.

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 authorisation.

You already have a root password set, so you can safely answer ‘n’.

Change the root password? [Y/n] y
New password:
Re-enter new password:
Sorry, passwords do not match.

New password:
Re-enter new password:
Sorry, passwords do not match.

New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
… Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB 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] n
… skipping.

By default, MariaDB 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…
ERROR 1008 (HY000) at line 1: Can’t drop database ‘test’; database doesn’t exist
… Failed! Not critical, keep moving…
– 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 MariaDB
installation should now be secure.

Thanks for using MariaDB!


Finally, its time to install PHP

PHP which stand for Hypertext Preprocessor is a widely used open-source general purpose scripting langue that is used for web development embeded with HTML.


Execute the command gived below to install PHP

yum install php php-mysql php-gd php-pear -y


Once installed we can test the php

Create the sample php file as test.php file in Apache document root folder i.e. /var/www/html/test.php as

vi /var/www/html/test.php and append the lines below:




Restart the Apache as

systemctl restart httpd.service.

You can navigate to http://server-ip-address/test.php which will display all the details about php such as version, build date, commands etc.




Rajkishor Maharjan has written 17 articles