Install LAMP in CentOS 7 and RHEL7


Let’s keep it easy. Linux is one of the best OS for building a server. To build a small Linux web server, you need the following packages – any Linux OS (here, it’s CentOS 7), Apache, MySQL, and PHP. This is why its called LAMP. Sometimes, people add phpMyAdmin to facilitate the MySQL tasks for beginners.

Let me explain step by step. Starting from my test machine, my VM is Centos 7.4 with IP=

Install Apache Webserver

CentOS 7 ships with Apache 2.4. It’s a basic package available on CentOS 7. Let’s install it the withfollowingollow command:

You see  something like this:

Now, configure your apache to start at boot time

If your firewall is activated, please add the following rules to make your servers to be accessible remotely.

Check if server listening on port 80

Ow!!! Server only listening on TCP6 . It’s not available via IP address. Run this command:

edit /etc/httpd/conf/httpd.conf



Restart Apache and check netstat

Everything looks fine. Now, visit your welcome page at  and see  the bellow result.

Install MySQL

CentOS is  using  MariaDB instead of MySQL package . MariaDB is open source and fully compatible with MySQL.

Install mariadb-server and client with the following command:

Enable MySQL service to start at boot and start it now.

Now, set passwords for the MySQL root :

Test you access and see the created databases

If you followed everything as said, all things should be fine.

Install PHP

Please note that PHP 7 is not yet supported  in CentOS 7. The only supported PHP version is 5.x.

To install the official PHP package just run

If you choose to install PHP 7.2, you have to  activate Remi and EPEL repository.

Now, let’s install PHP.

Test your PHP page and settings

Add these lines into the file.

Now, save and exit.

Restart apache and  check your PHP file on

To Install additional PHP 7.2 modules, run these commands.


Install phpMyAdmin

This chapter is optional. It’s just to help you to manager your databases via a web interface. This tool is mostly used by beginners and professionals as well.

Installing phpMyAdmin

phpMyAdmin is not normally accessible remotely from another PC or servers. That’s why you have to make some changes to make this possible.

Let’s edit phpMyAdmin.conf file using command line:

and adjust the bellow settings

Now, restart apache to load the new settings.

Now, check the changes :  http://IP/phpmyadmin  (

You can login with root access already. You can easily defined and create databases and users :

Please feel free to ask questions or comment on this article!!!

Spread the love
  • 7

PS. If you like this post please share it with your friends on the social networks using the buttons above.Thanks.


Please enter your comment!
Please enter your name here