Installation of Apache, MySQL, PHP (LAMP) on CentOS / RHEL

Installation of Apache, MySQL, PHP (LAMP)

LAMP (Linux, Apache, MySQL, PHP/Perl/Python) is an acronym denoting one of the most common software stacks for many of the web’s most popular applications. However, LAMP now refers to a generic software stack model and its components are largely interchangeable.

Step 1 : Apache Installation

The Apache HTTP Server is a free and open-source cross-platform web server software, released under the terms of Apache License 2.0. Apache is developed and maintained by an open community of developers under the auspices of the Apache Software Foundation.

To install the httpd Apache package, enter the following command into your terminal:

$ sudo yum install httpd yum-utils

Once the setup is finished, use the following command to start your Apache server:

$ sudo systemctl start httpd

By entering your public IP address or domain name in your web browser, you may check to see if your server is up and operating.

apache welcome page

To make Apache launch immediately after booting, use:

$ sudo systemctl enable httpd.service

Step 2 : MySQL installation

For a complete guide, follow steps in this tutorial: Install MySQL on CentOS/Redhat 7/6 & Fedora 31/30.

Step 3 : Install PHP

PHP is the part of our system that will process the code in order to show dynamic content. It can execute scripts, connect to our MySQL databases for information, and then provide the processed data to our web server for display.

Because the PHP version supplied by default on CentOS 7 and RedHat 7 servers is out of date, we’ll need to install a third-party package repository in order to download and install PHP 7+ on your CentOS 7 server. Remi is a prominent package repository that offers the most recent PHP versions for CentOS machines.

Run the following command to install the Remi repository for CentOS 7:

$ sudo yum install

Once installation is complete, you must run a command to enable the repository containing your preferred version of PHP. To verify that PHP 7+ releases are available in the Remi repository, run:

$ yum --disablerepo="*" --enablerepo="remi-safe" list php[7-9][0-9].x86_64

You will see the following output:

Output :
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * remi-safe:
Available Packages
php70.x86_64            2.0-1.el7.remi                    remi-safe
php71.x86_64            2.0-1.el7.remi                    remi-safe
php72.x86_64            2.0-1.el7.remi                    remi-safe
php73.x86_64            2.0-1.el7.remi                    remi-safe
php74.x86_64            1.0-3.el7.remi                    remi-safe
php80.x86_64            1.0-3.el7.remi                    remi-safe

In this tutorial, we will install PHP 7.4. To obtain PHP 7.4, use the following command to activate the proper Remi package:

$ sudo yum-config-manager --enable remi-php74

Now, we can use yum to install PHP as usual. The following command will install all of the packages required to get PHP 7.4 working in Apache and connected to MySQL-based databases:

$ sudo yum install php php-mysqlnd php-fpm

To ensure that PHP is installed as your preferred version, execute:

$ php --version
Output :
PHP 7.4.8 (cli) (built: Jul 9 2020 16:09:41) (NTS)
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
  with Zend OPcache v7.4.21, Copyright (c), by Zend Technologies

PHP has now been installed successfully on your machine.

Step 4 : Run PHP on Apache.

A document root will be created at /var/www/html by CentOS 7’s default Apache installation. It is not necessary to alter Apache’s default settings in order for PHP to function properly on your web server.

$ nano /var/www/html/info.php

When you’re done, save and exit the file.

Now let’s access the info file in :


php info page