How to install LAMP on CentOS 7.

share on:
install lamp on centos 7

A LAMP web stack consists of Linux Operating System, Apache web server, MySQL/MariaDB Database Server and PHP. It is a web stack in which we install necessary software so that it can be used for hosting web content.

For this tutorial, I am using DigitalOcean droplet with 512 MB RAM. DigitalOcean offers

If you are in a hurry to install LAMP on CentOS 7 to test something, there is a link to a simple script at the end of this Post.

About this guide:


Before installing anything we will first update our server.

[root@debyum ~]# yum update -y
[root@debyum ~]# yum install epel-release rsync pwgen curl wget unzip -y






First of all, we will install Apache 2.4 on CentOS 7.5 server.

[root@debyum ~]# yum install httpd -y


Setting  ServerName globally to Suppress Syntax Warnings.

Now, we will take care of an annoying warning message about not being able to reliably determine the server’s fully qualified domain name. This error appears during restarting Apache server in lamp web stack or when checking for syntax error.

This error appears during restarting Apache server in lamp web stack or when checking for syntax error.

This warning can be easily removed via:

[root@debyum ~]# echo "ServerName localhost" >> /etc/httpd/conf/httpd.conf



If you want to set your IP Address to your server name then you can use.

[root@debyum ~]# IPOFSERVER=ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/'
[root@debyum ~]# echo "ServerName $IPOFSERVER" >> /etc/httpd/conf/httpd.conf


Next, check for syntax errors by typing:

[root@debyum ~]# apachectl -t
Syntax OK


Finally, Restart Apache to put in place your changes:

[[email protected] ~]# systemctl start httpd


Allow Apache through Firewall.

We will allow Apache to communicate through Firewall.

[root@debyum ~]# firewall-cmd --zone=public --add-service=http --add-service=https --permanent
[root@debyum ~]# firewall-cmd --zone=public --add-port=80/tcp --add-port=443/tcp --permanent
[root@debyum ~]# firewall-cmd --reload


To check if Apache is working properly, you can always visit your IP-ADDRESS in your browser.

Or you can install elinks or w3m like packages to check apache’s working from command line.

[root@debyum ~]# yum install elinks -y
[root@debyum ~]# elinks http://server-ip-address



Install Latest MariaDB 10.3 in CentOS 7.

MariaDB is a truly Open Source Database management system created by MySQL’s original developers in 2009.

MariaDB is easy to install and configure just like MySQL and is currently the default database Management system in Centos 7. MariaDB is recommended for its official support.

 Also check this post: Complete guide on how to Install, Backup, Restore, Recover password in MySQL/MariaDB.

To simply install Latest MariaDB server we will create a repo file in  /etc/yum.repos.d  directory and enable that repo for MariaDB 10.3.

[root@debyum ~]# cat <<'EOF' >> /etc/yum.repos.d/MariaDB.repo
name = MariaDB
baseurl =


Install MariaDB 10.3.

Now that we have created a repo. , we can easily install Latest MariaDB in CentOS 7 server.

Now, Update the system and then install the MariaDB client and Server.

[root@debyum ~]# yum -y install MariaDB-server MariaDB-client


Also, Enable the mariadb.service to start at boot and then start the mariadb.service.

[root@debyum ~]# systemctl enable mariadb.service
[root@debyum ~]# systemctl start mariadb.service


Starting MariaDB and Double-checking it’s status.

[root@debyum ~]# systemctl status mariadb.service


Check the version of MariaDB server.

[root@debyum ~]# mysql -V
mysql  Ver 15.1 Distrib 10.3.8-MariaDB, for Linux (x86_64) using readline 5.1



Securing the Database Server.

Now, We need to secure the Database server by running this script  ( mysql_secure_installation ) in the shell.

[root@debyum ~]# mysql_secure_installation
Enter current password for root (enter for none):
Set root password? [Y/n]   y

New password:
Re-enter new password:

Remove anonymous users? [Y/n]   y

**** If you don't want to access your database remotely then enter 'y' otherwise enter 'n' ****

Disallow root login remotely? [Y/n]   y

Remove test database and access to it? [Y/n]   y

Reload privilege tables now? [Y/n]   y


Stopping MySQL Service.

Also, If you want to stop MySQL service use,

[root@debyum ~]# systemctl stop mariadb.service



Install PHP 7.2 on CentOS 7.

PHP is used to run scripts, connect to the Database server ( MySQL/MariaDB ) to fetch data and process all the data to display dynamic content.

Also, check this post:> Top 10 PHP Security Best Practices For Linux Sys Administrators.

Also, we will install extra packages so that our PHP can connect with MySQL/MariaDB database. These packages are often required by many CMS and HRM applications for example WordPress.

[root@debyum ~]# yum localinstall



After installation you can check the list of Remi repos available for PHP in /etc/yum.repos.d directory.

[root@debyum ~]# ls -l /etc/yum.repos.d/
total 80
-rw-r--r--. 1 root root 1664 May 17 19:23 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 May 17 19:23 CentOS-CR.repo
-rw-r--r--. 1 root root 649 May 17 19:23 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root 314 May 17 19:23 CentOS-fasttrack.repo
-rw-r--r--. 1 root root 630 May 17 19:23 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 May 17 19:23 CentOS-Sources.repo
-rw-r--r--. 1 root root 4768 May 17 19:23 CentOS-Vault.repo
-rw-r--r--. 1 root root 951 Oct 2 2017 epel.repo
-rw-r--r--. 1 root root 1050 Oct 2 2017 epel-testing.repo
-rw-r--r--. 1 root root 446 Jun 19 13:58 remi-glpi91.repo
-rw-r--r--. 1 root root 446 Jun 19 13:58 remi-glpi92.repo
-rw-r--r--. 1 root root 446 Jun 19 13:58 remi-glpi93.repo
-rw-r--r--. 1 root root 456 Jun 19 13:58 remi-php54.repo
-rw-r--r--. 1 root root 1314 Jun 19 13:58 remi-php70.repo
-rw-r--r--. 1 root root 1314 Jun 19 13:58 remi-php71.repo
-rw-r--r--. 1 root root 1314 Jun 19 13:58 remi-php72.repo
-rw-r--r--. 1 root root 1314 Jun 19 13:58 remi-php73.repo
-rw-r--r--. 1 root root 2605 Jun 19 13:58 remi.repo
-rw-r--r--. 1 root root 750 Jun 19 13:58 remi-safe.repo


We can enable Remi repo related to a particualar php version.

  • For php 5.6, we can enable remi-php56 repo.
  • For php 7.0, we can enable remi-php70 repo. Then remi-php71 for PHp7.1 and so on till Php 7.3.

Here we are going to Install latest stable PHP 7.2 on our server so we will enable the remi-php72 repo.

We can enable these repos by manually editing the repo file directly in /etc/yum.repos.d directory.

For example to enable PHP 7.2, we need to edit remi-php72.repo file and enable the [remi-php72] section.

[root@debyum ~]# vi /etc/yum.repos.d/remi-php72.repo

name=Remi's PHP 7.2 RPM repository for Enterprise Linux 7 - $basearch


Or we can use yum-config-manager from yum-utils package to enable the repo easily.

[root@debyum ~]# yum-config-manager --enable remi-php72
Loaded plugins: fastestmirror
======================================================== repo: remi-php72 =========================================================


Update and check the version of PHP on the server.
[root@debyum ~]# yum update


Then check the version of PHP and PHP-FPM package available on server.

[root@debyum ~]# yum info php
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base:
* epel:
* extras:
* remi-php72:
* remi-safe:
* updates:
remi-php72 | 2.9 kB 00:00:00 
remi-php72/primary_db | 195 kB 00:00:08 
Available Packages
Name : php
Arch : x86_64
Version : 7.2.8
Release : 1.el7.remi
Size : 3.2 M
Repo : remi-php72
Summary : ........


[root@debyum ~]# yum info php-fpm
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base:
* epel:
* extras:
* remi-php72:
* remi-safe:
* updates:
Available Packages
Name : php-fpm
Arch : x86_64
Version : 7.2.8
Release : 1.el7.remi
Size : 1.7 M
Repo : remi-php72
Summary : ......


Check PHP version.

[root@debyum ~]# php -v
PHP 7.2.8 (cli) (built: Jul 17 2018 09:50:46) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.8, Copyright (c) 1999-2018, by Zend Technologies


Restart Apache server.

Finally, Restart Apache web server.

[root@debyum ~]# systemctl restart httpd



With LAMP web stack installed on CentOS 7, we can now install any type of CMS or HRM like WordPress or PrestaShop.

Lamp web development stack is easy to install and you should definitely try it.

And if you want are in a little bit hurry to install LAMP in CentOS 7 test server then you can visit Page 2 for a simple LAMP script.

I have tried to cover all the basic to advance concepts with their examples. Still, if I have missed anything please update us through comment box. I will keep updating the same based on feedback’s received.


Review overview



share on:


Hello there, My name is Rishi Guleria and I work as a Linux system administrator. I have created this blog to share what I have learned so far and to learn new things. Good Day. :)

Leave a Response

share on: