LAMP install on RHEL/CentOS

What is LAMP?

LAMP is an acronym that refers to various free and open source software that is often referred to as a stack. In general terms the acronym LAMP refers to:

Linux: The Linux Operating System
Apache: HTTP Web Server
MariaDB, MySQL or MongoDB: Database
PHP, Python or Perl: Scripting languages used for creating dynamic web page content

LAMP loosely defines which components comprise the stack, however, it is down to individual preferences/requirements as to which components you choose to make your stack.

All of the components needed should be available within your chosen Operating Systems repositories.

Linux Operating System

Linux is the Operating system. This can be any number of popular distributions. The most common within a LAMP stack are CentOS, Red Hat (RHEL), Debian and Ubuntu. In this example, I am using a RHEL 8 operating system.

For instructions on how to install the RHEL Operating System, follow the link: RHEL 8 Installation.

For instructions on how to install the CentOS Operating System, follow the link: CentOS 8 Installation.

For instructions on how to install the Ubuntu Operating System, follow the link: Ubuntu Server Installation.

For instructions on how to install the Debian Operating System, follow the link: Debian Installation.

Apache Web Server

To install the "Apache Web Server" on a RHEL 8 Server, follow the steps below:

To install an Apache web server, issue the following command on your server: "dnf install httpd -y"

# dnf install httpd -y
Updating Subscription Management repositories.
Last metadata expiration check: 0:16:36 ago on Sun 30 May 2021 16:34:04 BST.
Dependencies resolved.
 Package                 Arch        Version                                        Repository                             Size
 httpd                   x86_64      2.4.37-39.module+el8.4.0+9658+b87b2deb         rhel-8-for-x86_64-appstream-rpms      1.4 M
Installing dependencies:
 apr                     x86_64      1.6.3-11.el8                                   rhel-8-for-x86_64-appstream-rpms      125 k
 apr-util                x86_64      1.6.1-6.el8                                    rhel-8-for-x86_64-appstream-rpms      105 k
 httpd-filesystem        noarch      2.4.37-39.module+el8.4.0+9658+b87b2deb         rhel-8-for-x86_64-appstream-rpms       38 k
 httpd-tools             x86_64      2.4.37-39.module+el8.4.0+9658+b87b2deb         rhel-8-for-x86_64-appstream-rpms      106 k
 mod_http2               x86_64      1.15.7-3.module+el8.4.0+8625+d397f3da          rhel-8-for-x86_64-appstream-rpms      154 k
 redhat-logos-httpd      noarch      84.4-1.el8                                     rhel-8-for-x86_64-baseos-rpms          29 k
Installing weak dependencies:
 apr-util-bdb            x86_64      1.6.1-6.el8                                    rhel-8-for-x86_64-appstream-rpms       25 k
 apr-util-openssl        x86_64      1.6.1-6.el8                                    rhel-8-for-x86_64-appstream-rpms       27 k
Enabling module streams:
 httpd                               2.4                                                                                       

Transaction Summary
Install  9 Packages

Total download size: 2.0 M
Installed size: 5.4 M
Downloading Packages:
(1/9): apr-util-openssl-1.6.1-6.el8.x86_64.rpm                                                   47 kB/s |  27 kB     00:00    
(2/9): apr-util-bdb-1.6.1-6.el8.x86_64.rpm                                                       32 kB/s |  25 kB     00:00    
(3/9): redhat-logos-httpd-84.4-1.el8.noarch.rpm                                                  37 kB/s |  29 kB     00:00    
(4/9): apr-util-1.6.1-6.el8.x86_64.rpm                                                          410 kB/s | 105 kB     00:00    
(5/9): httpd-filesystem-2.4.37-39.module+el8.4.0+9658+b87b2deb.noarch.rpm                       174 kB/s |  38 kB     00:00    
(6/9): apr-1.6.3-11.el8.x86_64.rpm                                                              478 kB/s | 125 kB     00:00    
(7/9): httpd-tools-2.4.37-39.module+el8.4.0+9658+b87b2deb.x86_64.rpm                            393 kB/s | 106 kB     00:00    
(8/9): httpd-2.4.37-39.module+el8.4.0+9658+b87b2deb.x86_64.rpm                                  2.6 MB/s | 1.4 MB     00:00    
(9/9): mod_http2-1.15.7-3.module+el8.4.0+8625+d397f3da.x86_64.rpm                               421 kB/s | 154 kB     00:00    
Total                                                                                           1.5 MB/s | 2.0 MB     00:01     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                        1/1 
  Installing       : apr-1.6.3-11.el8.x86_64                                                                                1/9 
  Running scriptlet: apr-1.6.3-11.el8.x86_64                                                                                1/9 
  Installing       : apr-util-bdb-1.6.1-6.el8.x86_64                                                                        2/9 
  Installing       : apr-util-1.6.1-6.el8.x86_64                                                                            3/9 
  Running scriptlet: apr-util-1.6.1-6.el8.x86_64                                                                            3/9 
  Installing       : apr-util-openssl-1.6.1-6.el8.x86_64                                                                    4/9 
  Installing       : httpd-tools-2.4.37-39.module+el8.4.0+9658+b87b2deb.x86_64                                              5/9 
  Running scriptlet: httpd-filesystem-2.4.37-39.module+el8.4.0+9658+b87b2deb.noarch                                         6/9 
  Installing       : httpd-filesystem-2.4.37-39.module+el8.4.0+9658+b87b2deb.noarch                                         6/9 
  Installing       : redhat-logos-httpd-84.4-1.el8.noarch                                                                   7/9 
  Installing       : mod_http2-1.15.7-3.module+el8.4.0+8625+d397f3da.x86_64                                                 8/9 
  Installing       : httpd-2.4.37-39.module+el8.4.0+9658+b87b2deb.x86_64                                                    9/9 
  Running scriptlet: httpd-2.4.37-39.module+el8.4.0+9658+b87b2deb.x86_64                                                    9/9 
  Verifying        : redhat-logos-httpd-84.4-1.el8.noarch                                                                   1/9 
  Verifying        : apr-util-openssl-1.6.1-6.el8.x86_64                                                                    2/9 
  Verifying        : apr-util-bdb-1.6.1-6.el8.x86_64                                                                        3/9 
  Verifying        : apr-util-1.6.1-6.el8.x86_64                                                                            4/9 
  Verifying        : apr-1.6.3-11.el8.x86_64                                                                                5/9 
  Verifying        : httpd-filesystem-2.4.37-39.module+el8.4.0+9658+b87b2deb.noarch                                         6/9 
  Verifying        : httpd-2.4.37-39.module+el8.4.0+9658+b87b2deb.x86_64                                                    7/9 
  Verifying        : mod_http2-1.15.7-3.module+el8.4.0+8625+d397f3da.x86_64                                                 8/9 
  Verifying        : httpd-tools-2.4.37-39.module+el8.4.0+9658+b87b2deb.x86_64                                              9/9 
Installed products updated.

  apr-1.6.3-11.el8.x86_64                                      apr-util-1.6.1-6.el8.x86_64                                      
  apr-util-bdb-1.6.1-6.el8.x86_64                              apr-util-openssl-1.6.1-6.el8.x86_64                              
  httpd-2.4.37-39.module+el8.4.0+9658+b87b2deb.x86_64          httpd-filesystem-2.4.37-39.module+el8.4.0+9658+b87b2deb.noarch   
  httpd-tools-2.4.37-39.module+el8.4.0+9658+b87b2deb.x86_64    mod_http2-1.15.7-3.module+el8.4.0+8625+d397f3da.x86_64           


The Apache Web server is known on RHEL based systems as "httpd".

To make sure the Web Server is started automatically at system boot time, you must issue the following command:

systemctl enable httpd

# systemctl enable httpd
Created symlink /etc/systemd/system/ → /usr/lib/systemd/system/httpd.service.

# systemctl is-enabled httpd

To start the Web Server, you will need to issue the following command:

systemctl start httpd

# systemctl start httpd

# systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2021-05-30 16:55:57 BST; 7s ago
     Docs: man:httpd.service(8)
 Main PID: 24581 (httpd)
   Status: "Started, listening on: port 80"
    Tasks: 213 (limit: 9188)
   Memory: 30.9M
   CGroup: /system.slice/httpd.service
           ├─24581 /usr/sbin/httpd -DFOREGROUND
           ├─24582 /usr/sbin/httpd -DFOREGROUND
           ├─24583 /usr/sbin/httpd -DFOREGROUND
           ├─24584 /usr/sbin/httpd -DFOREGROUND
           └─24585 /usr/sbin/httpd -DFOREGROUND

May 30 16:55:57 rhel08a systemd[1]: Starting The Apache HTTP Server...
May 30 16:55:57 rhel08a httpd[24581]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, us>
May 30 16:55:57 rhel08a systemd[1]: Started The Apache HTTP Server.
May 30 16:55:57 rhel08a httpd[24581]: Server configured, listening on: port 80

From the above we can see that the "httpd" service has been started. The status was displayed by issuing the following status command:

systemctl status httpd

configuration files

The main configuration files can be found under the following location: /etc/httpd/conf/httpd.conf The main document area is located in the following path: /var/www/html

Install MariaDB

MariaDB is a fork of MySQL and is created by the founders of MySQL. To install MariaDB on a RHEL 8 server, issue the following command:

dnf install mariadb mariadb-server -y

MariaDB will be installed along with any dependencies.

# dnf install mariadb mariadb-server -y
Updating Subscription Management repositories.
Last metadata expiration check: 0:41:38 ago on Sun 30 May 2021 16:34:04 BST.
Dependencies resolved.
 Package                    Arch   Version                                    Repository                        Size
 mariadb                    x86_64 3:10.3.28-1.module+el8.3.0+10472+7adc332a  rhel-8-for-x86_64-appstream-rpms 6.0 M
 mariadb-server             x86_64 3:10.3.28-1.module+el8.3.0+10472+7adc332a  rhel-8-for-x86_64-appstream-rpms  16 M
Installing dependencies:
 mariadb-common             x86_64 3:10.3.28-1.module+el8.3.0+10472+7adc332a  rhel-8-for-x86_64-appstream-rpms  64 k
 mariadb-connector-c        x86_64 3.1.11-2.el8_3                             rhel-8-for-x86_64-appstream-rpms 200 k

The above is only an extract of the full output.

Enabling and Starting MariaDB

Once you have successfully installed MariaDB and any dependencies, you will need to enable the service and start the service with the following commands:

Start MariaDB
systemctl start mariadb

Enable MariaDB to autostart at system start-up
systemctl enable mariadb

Verify mariaDB is running and enabled
systemctl status mariadb

# systemctl start mariadb

# systemctl enable mariadb
Created symlink /etc/systemd/system/mysql.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/mysqld.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/ → /usr/lib/systemd/system/mariadb.service.

# systemctl status mariadb
● mariadb.service - MariaDB 10.3 database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2021-05-30 17:23:03 BST; 1min 6s ago
     Docs: man:mysqld(8)
 Main PID: 4388 (mysqld)
   Status: "Taking your SQL requests now..."
    Tasks: 30 (limit: 9188)
   Memory: 84.0M
   CGroup: /system.slice/mariadb.service
           └─4388 /usr/libexec/mysqld --basedir=/usr

May 30 17:23:03 rhel08a mysql-prepare-db-dir[4284]: See the MariaDB Knowledgebase at or the
May 30 17:23:03 rhel08a mysql-prepare-db-dir[4284]: MySQL manual for more instructions.
May 30 17:23:03 rhel08a mysql-prepare-db-dir[4284]: Please report any problems at
May 30 17:23:03 rhel08a mysql-prepare-db-dir[4284]: The latest information about MariaDB is available at http://mari>
May 30 17:23:03 rhel08a mysql-prepare-db-dir[4284]: You can find additional information about the MySQL part at:
May 30 17:23:03 rhel08a mysql-prepare-db-dir[4284]:
May 30 17:23:03 rhel08a mysql-prepare-db-dir[4284]: Consider joining MariaDB's strong and vibrant community:
May 30 17:23:03 rhel08a mysql-prepare-db-dir[4284]:
May 30 17:23:03 rhel08a mysqld[4388]: 2021-05-30 17:23:03 0 [Note] /usr/libexec/mysqld (mysqld 10.3.28-MariaDB) star>
May 30 17:23:03 rhel08a systemd[1]: Started MariaDB 10.3 database server.

Enabling Security

By default our MariaDB installation has no passwords set. To rectify this, we can run a special script called:

To secure your MariaDB, reply to the questions asked. Generally you only need to respond "y" to the first question asked "Set root password". All other questions you can press "Enter" to. Once you have responded to each question, you will have secured your MariaDB instance by removing anonymous user access, disabling remote root login and removing the test database and access to it.

# mysql_secure_installation 


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.

Set root password? [Y/n] y
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] 
 ... 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] 
 ... Success!

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] 
 - 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] 
 ... 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!

Verify MariaDB access

To verify your access to the MariaDB, you can login with the following command:

mysql -u root -p

You will need to provide the password you created in the previous step to login.

# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 16
Server version: 10.3.28-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> exit

Once you have logged in successfully, you issue the command "exit" to exit.

Install PHP

One of the most popular scripting languages used to create dynamic web pages is "PHP". To install the PHP language along with some popular modules issue the command below:

dnf install php php-mysqlnd php-common php-mbstring php-devel php-gd php-xml -y

Below is a partial extract of the output showing the packages being installed along with their dependencies.

# dnf install php php-mysqlnd php-common php-mbstring php-devel php-gd php-xml -y
Updating Subscription Management repositories.
Last metadata expiration check: 1:14:08 ago on Sun 30 May 2021 16:34:04 BST.
Dependencies resolved.
 Package              Arch      Version                                    Repository                           Size
 php                  x86_64    7.2.24-1.module+el8.2.0+4601+7c76a223      rhel-8-for-x86_64-appstream-rpms    1.5 M
 php-common           x86_64    7.2.24-1.module+el8.2.0+4601+7c76a223      rhel-8-for-x86_64-appstream-rpms    662 k
 php-devel            x86_64    7.2.24-1.module+el8.2.0+4601+7c76a223      rhel-8-for-x86_64-appstream-rpms    712 k
 php-gd               x86_64    7.2.24-1.module+el8.2.0+4601+7c76a223      rhel-8-for-x86_64-appstream-rpms     84 k
 php-mbstring         x86_64    7.2.24-1.module+el8.2.0+4601+7c76a223      rhel-8-for-x86_64-appstream-rpms    580 k
 php-mysqlnd          x86_64    7.2.24-1.module+el8.2.0+4601+7c76a223      rhel-8-for-x86_64-appstream-rpms    191 k
 php-xml              x86_64    7.2.24-1.module+el8.2.0+4601+7c76a223      rhel-8-for-x86_64-appstream-rpms    189 k
Installing dependencies:
 autoconf             noarch    2.69-27.el8                                rhel-8-for-x86_64-appstream-rpms    710 k
 automake             noarch    1.16.1-7.el8                               rhel-8-for-x86_64-appstream-rpms    713 k
 cpp                  x86_64    8.4.1-1.el8                                rhel-8-for-x86_64-appstream-rpms     10 M
 gcc                  x86_64    8.4.1-1.el8                                rhel-8-for-x86_64-appstream-rpms     23 M
 gcc-c++              x86_64    8.4.1-1.el8                                rhel-8-for-x86_64-appstream-rpms     12 M
 gd                   x86_64    2.2.5-7.el8                                rhel-8-for-x86_64-appstream-rpms    144 k
 glibc-devel          x86_64    2.28-151.el8                               rhel-8-for-x86_64-baseos-rpms       1.0 M
 glibc-headers        x86_64    2.28-151.el8                               rhel-8-for-x86_64-baseos-rpms       478 k
 isl                  x86_64    0.16.1-6.el8                               rhel-8-for-x86_64-appstream-rpms    841 k
 jbigkit-libs         x86_64    2.1-14.el8                                 rhel-8-for-x86_64-appstream-rpms     55 k
 kernel-headers       x86_64    4.18.0-305.el8                             rhel-8-for-x86_64-baseos-rpms       7.1 M
 libXpm               x86_64    3.5.12-8.el8                               rhel-8-for-x86_64-appstream-rpms     58 k
 libjpeg-turbo        x86_64    1.5.3-10.el8                               rhel-8-for-x86_64-appstream-rpms    156 k
 libmpc               x86_64    1.1.0-9.1.el8                              rhel-8-for-x86_64-appstream-rpms     61 k
 libstdc++-devel      x86_64    8.4.1-1.el8                                rhel-8-for-x86_64-appstream-rpms    2.0 M
 libtiff              x86_64    4.0.9-18.el8                               rhel-8-for-x86_64-appstream-rpms    188 k
 libtool              x86_64    2.4.6-25.el8                               rhel-8-for-x86_64-appstream-rpms    709 k
 libwebp              x86_64    1.0.0-1.el8                                rhel-8-for-x86_64-appstream-rpms    273 k
 libxcrypt-devel      x86_64    4.1.1-4.el8                                rhel-8-for-x86_64-baseos-rpms        25 k
 m4                   x86_64    1.4.18-7.el8                               rhel-8-for-x86_64-baseos-rpms       223 k
 nginx-filesystem     noarch    1:1.14.1-9.module+el8.0.0+4108+af250afe    rhel-8-for-x86_64-appstream-rpms     24 k
 pcre-cpp             x86_64    8.42-4.el8                                 rhel-8-for-x86_64-baseos-rpms        47 k
 pcre-devel           x86_64    8.42-4.el8                                 rhel-8-for-x86_64-baseos-rpms       551 k
 pcre-utf16           x86_64    8.42-4.el8                                 rhel-8-for-x86_64-baseos-rpms       195 k
 pcre-utf32           x86_64    8.42-4.el8                                 rhel-8-for-x86_64-baseos-rpms       186 k
 perl-Thread-Queue    noarch    3.13-1.el8                                 rhel-8-for-x86_64-appstream-rpms     24 k
 php-cli              x86_64    7.2.24-1.module+el8.2.0+4601+7c76a223      rhel-8-for-x86_64-appstream-rpms    3.1 M
 php-pdo              x86_64    7.2.24-1.module+el8.2.0+4601+7c76a223      rhel-8-for-x86_64-appstream-rpms    123 k
Installing weak dependencies:
 php-fpm              x86_64    7.2.24-1.module+el8.2.0+4601+7c76a223      rhel-8-for-x86_64-appstream-rpms    1.6 M
Enabling module streams:
 nginx                          1.14                                                                                
 php                            7.2                                                                                 

Transaction Summary
Install  36 Packages

Total download size: 71 M
Installed size: 186 M

Once the above packages have been installed successfully, you will need to issue the following commands:

Start php-fpm
systemctl start php-fpm

Enable php-fpm
systemctl enable php-fpm

Verify Status php-fpm
systemctl status php-fpm

[root@rhel08a ~]# systemctl start php-fpm
[root@rhel08a ~]# systemctl enable php-fpm
Created symlink /etc/systemd/system/ → /usr/lib/systemd/system/php-fpm.service.
[root@rhel08a ~]# systemctl status php-fpm
● php-fpm.service - The PHP FastCGI Process Manager
   Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2021-05-30 17:54:11 BST; 40s ago
 Main PID: 5319 (php-fpm)
   Status: "Processes active: 0, idle: 5, Requests: 0, slow: 0, Traffic: 0req/sec"
    Tasks: 6 (limit: 9188)
   Memory: 14.4M
   CGroup: /system.slice/php-fpm.service
           ├─5319 php-fpm: master process (/etc/php-fpm.conf)
           ├─5320 php-fpm: pool www
           ├─5321 php-fpm: pool www
           ├─5322 php-fpm: pool www
           ├─5323 php-fpm: pool www
           └─5324 php-fpm: pool www

May 30 17:54:11 rhel08a systemd[1]: Starting The PHP FastCGI Process Manager...
May 30 17:54:11 rhel08a systemd[1]: Started The PHP FastCGI Process Manager.

php-fm allows you tu run secure, fast, dependable PHP code on your Apache Web Server.

Test PHP with Apache Web Server

Before we actually carry out a test, we will need to restart the Apache Web Server with the following command:

systemctl restart httpd

If you are running SELinux, then you will also need to issue the following command:

setsebool -P httpd_execmem 1

The above command instructs SELinux to allow Apache to run php-fm instructions

To Test that PHP is working correctly we can create a test file that when executed will display information relating to the current version of PHP.

Create a file named /var/www/html/test.php with the following phpinfo() function inside php quotes:

<?php phpinfo(); ?>

To test the file that we have just created, we need to type the ip address along with our test file name into a web browser of your choice. In this example the IP address is

So we enter:

PHP Apache test Page