Install LAMP Stack on RHEL 8 Server - CentLinux


Sunday, 7 July 2019

Install LAMP Stack on RHEL 8 Server

Install LAMP Stack on RHEL 8 Server

LAMP is the most widely used software service stack, used to deploy PHP based web applications. LAMP is named as acronym, derived from first letter of four original open-source components i.e. L from Linux, A from Apache, M from MySQL and P from PHP.

In this article, we are installing LAMP Stack on Red Hat Enterprise Linux (RHEL) 8 Server. Here, we have selected Red Hat Enterprise Linux (RHEL) 8, Apache HTTP Server 2.4, MySQL 8.0 and PHP 7.2 as the LAMP Stack components.


This Article Provides:


    Environment Specification:

    A RHEL 8 based virtual machine is being used in this article. The specifications are:

    • CPU - 3.4 Ghz (2 cores)
    • Memory - 2 GB
    • Storage - 20 GB
    • Operating System - Red Hat Enterprise Linux (RHEL) 8
    • Hostname -
    • IP Address -

    A Local YUM/DNF repository is configured, so we can install required packages without having an active Red Hat subscription.


    Installing Apache HTTP Server 2.4 on RHEL 8:

    Connect with using ssh as root user.

    Since, we have already configured local yum repository, therefore, we can easily install Apache HTTP Server using dnf command.

    [root@rhel-8-lamp ~]# dnf install -y httpd Updating Subscription Management repositories. Unable to read consumer identity This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. Last metadata expiration check: 0:14:28 ago on Sun 07 Jul 2019 08:17:12 AM PKT. Dependencies resolved. ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: httpd x86_64 2.4.37-10.module+el8+2764+7127e69e localyum_AppStream 1.4 M Installing dependencies: apr x86_64 1.6.3-9.el8 localyum_AppStream 125 k apr-util x86_64 1.6.1-6.el8 localyum_AppStream 105 k httpd-filesystem noarch 2.4.37-10.module+el8+2764+7127e69e localyum_AppStream 34 k httpd-tools x86_64 2.4.37-10.module+el8+2764+7127e69e localyum_AppStream 101 k mod_http2 x86_64 1.11.3-1.module+el8+2443+605475b7 localyum_AppStream 156 k mailcap noarch 2.1.48-3.el8 localyum_BaseOS 39 k redhat-logos-httpd noarch 80.7-1.el8 localyum_BaseOS 25 k Installing weak dependencies: apr-util-bdb x86_64 1.6.1-6.el8 localyum_AppStream 25 k apr-util-openssl x86_64 1.6.1-6.el8 localyum_AppStream 27 k Enabling module streams: httpd 2.4 Transaction Summary ================================================================================ Install 10 Packages Total size: 2.0 M Installed size: 5.5 M Downloading Packages: Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Installing : apr-1.6.3-9.el8.x86_64 1/10 Running scriptlet: apr-1.6.3-9.el8.x86_64 1/10 Installing : apr-util-bdb-1.6.1-6.el8.x86_64 2/10 Installing : apr-util-openssl-1.6.1-6.el8.x86_64 3/10 Installing : apr-util-1.6.1-6.el8.x86_64 4/10 Running scriptlet: apr-util-1.6.1-6.el8.x86_64 4/10 Installing : httpd-tools-2.4.37-10.module+el8+2764+7127e69e.x86 5/10 Installing : redhat-logos-httpd-80.7-1.el8.noarch 6/10 Installing : mailcap-2.1.48-3.el8.noarch 7/10 Running scriptlet: httpd-filesystem-2.4.37-10.module+el8+2764+7127e69 8/10 Installing : httpd-filesystem-2.4.37-10.module+el8+2764+7127e69 8/10 Installing : mod_http2-1.11.3-1.module+el8+2443+605475b7.x86_64 9/10 Installing : httpd-2.4.37-10.module+el8+2764+7127e69e.x86_64 10/10 Running scriptlet: httpd-2.4.37-10.module+el8+2764+7127e69e.x86_64 10/10 Verifying : apr-1.6.3-9.el8.x86_64 1/10 Verifying : apr-util-1.6.1-6.el8.x86_64 2/10 Verifying : apr-util-bdb-1.6.1-6.el8.x86_64 3/10 Verifying : apr-util-openssl-1.6.1-6.el8.x86_64 4/10 Verifying : httpd-2.4.37-10.module+el8+2764+7127e69e.x86_64 5/10 Verifying : httpd-filesystem-2.4.37-10.module+el8+2764+7127e69 6/10 Verifying : httpd-tools-2.4.37-10.module+el8+2764+7127e69e.x86 7/10 Verifying : mod_http2-1.11.3-1.module+el8+2443+605475b7.x86_64 8/10 Verifying : mailcap-2.1.48-3.el8.noarch 9/10 Verifying : redhat-logos-httpd-80.7-1.el8.noarch 10/10 Installed products updated. Installed: httpd-2.4.37-10.module+el8+2764+7127e69e.x86_64 apr-util-bdb-1.6.1-6.el8.x86_64 apr-util-openssl-1.6.1-6.el8.x86_64 apr-1.6.3-9.el8.x86_64 apr-util-1.6.1-6.el8.x86_64 httpd-filesystem-2.4.37-10.module+el8+2764+7127e69e.noarch httpd-tools-2.4.37-10.module+el8+2764+7127e69e.x86_64 mod_http2-1.11.3-1.module+el8+2443+605475b7.x86_64 mailcap-2.1.48-3.el8.noarch redhat-logos-httpd-80.7-1.el8.noarch Complete!

    Enable and start httpd.service.

    [root@rhel-8-lamp ~]# systemctl enable httpd.service Created symlink /etc/systemd/system/ â /usr/lib/systemd/system/httpd.service. [root@rhel-8-lamp ~]# systemctl start httpd.service

    Allow HTTP service in Linux firewall.

    [root@rhel-8-lamp ~]# firewall-cmd --permanent --add-service=http success [root@rhel-8-lamp ~]# firewall-cmd --reload success

    Browse URL using a client's browser.


    Apache HTTP Server has been installed and running on Red Hat Enterprise Linux (RHEL) 8.


    Installing MySQL Database 8.0 on RHEL 8:

    For database back-end installation, we can choose between MySQL and MariaDB.

    Since we have already used MariaDB in our previous article Install LEMP Stack on RHEL8 Server, therefore, we are installing MySQL this time.

    MySQL 8.0 is available in local AppStream repository, therefore, let's install it using dnf command.

    [root@rhel-8-lamp ~]# dnf install -y mysql-server ... Installed: mysql-server-8.0.13-1.module+el8+2558+036183ec.x86_64 perl-IO-Socket-IP-0.39-5.el8.noarch perl-IO-Socket-SSL-2.060-2.el8.noarch perl-Mozilla-CA-20160104-7.el8.noarch mariadb-connector-c-config-3.0.7-1.el8.noarch mecab-0.996-1.module+el8+2459+7cb96738.9.x86_64 mysql-8.0.13-1.module+el8+2558+036183ec.x86_64 mysql-common-8.0.13-1.module+el8+2558+036183ec.x86_64 mysql-errmsg-8.0.13-1.module+el8+2558+036183ec.x86_64 perl-Digest-1.17-395.el8.noarch perl-Digest-MD5-2.55-396.el8.x86_64 perl-Net-SSLeay-1.85-6.el8.x86_64 perl-URI-1.73-3.el8.noarch perl-libnet-3.11-3.el8.noarch protobuf-lite-3.5.0-7.el8.x86_64 perl-Carp-1.42-396.el8.noarch perl-Data-Dumper-2.167-399.el8.x86_64 perl-Encode-4:2.97-3.el8.x86_64 perl-Errno-1.28-416.el8.x86_64 perl-Exporter-5.72-396.el8.noarch perl-File-Path-2.15-2.el8.noarch perl-File-Temp-0.230.600-1.el8.noarch perl-Getopt-Long-1:2.50-4.el8.noarch perl-HTTP-Tiny-0.074-1.el8.noarch perl-IO-1.38-416.el8.x86_64 perl-MIME-Base64-3.15-396.el8.x86_64 perl-PathTools-3.74-1.el8.x86_64 perl-Pod-Escapes-1:1.07-395.el8.noarch perl-Pod-Perldoc-3.28-396.el8.noarch perl-Pod-Simple-1:3.35-395.el8.noarch perl-Pod-Usage-4:1.69-395.el8.noarch perl-Scalar-List-Utils-3:1.49-2.el8.x86_64 perl-Socket-4:2.027-2.el8.x86_64 perl-Storable-1:3.11-3.el8.x86_64 perl-Term-ANSIColor-4.06-396.el8.noarch perl-Term-Cap-1.17-395.el8.noarch perl-Text-ParseWords-3.30-395.el8.noarch perl-Text-Tabs+Wrap-2013.0523-395.el8.noarch perl-Time-Local-1:1.280-1.el8.noarch perl-Unicode-Normalize-1.25-396.el8.x86_64 perl-constant-1.33-396.el8.noarch perl-interpreter-4:5.26.3-416.el8.x86_64 perl-libs-4:5.26.3-416.el8.x86_64 perl-macros-4:5.26.3-416.el8.x86_64 perl-parent-1:0.237-1.el8.noarch perl-podlators-4.11-1.el8.noarch perl-threads-1:2.21-2.el8.x86_64 perl-threads-shared-1.58-2.el8.x86_64 Complete!

    Start and enable MySQL service.

    [root@rhel-8-lamp ~]# systemctl enable mysqld.service Created symlink /etc/systemd/system/ â /usr/lib/systemd/system/mysqld.service. [root@rhel-8-lamp ~]# systemctl start mysqld.service

    Configure and secure MySQL database instance as follows.

    [root@rhel-8-lamp ~]# mysql_secure_installation Securing the MySQL server deployment. Connecting to MySQL using a blank password. VALIDATE PASSWORD COMPONENT can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD component? Press y|Y for Yes, any other key for No: y There are three levels of password validation policy: LOW Length >= 8 MEDIUM Length >= 8, numeric, mixed case, and special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary file Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2 Please set the password for root here. New password: Re-enter new password: Estimated strength of the password: 100 Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL 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? (Press y|Y for Yes, any other key for No) : 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? (Press y|Y for Yes, any other key for No) : y Success. By default, MySQL 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? (Press y|Y for Yes, any other key for No) : y - 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? (Press y|Y for Yes, any other key for No) : y Success. All done!

    Verify MySQL database installation using following command.

    [root@rhel-8-lamp ~]# mysql -e "SHOW DATABASES;" -p Enter password: +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+

    MySQL Database 8.0 has been installed on Red Hat Enterprise Linux (RHEL) 8.


    Installing PHP 7.2 on RHEL 8:

    In local AppStream repository, PHP 7.2 is available, therefore, we can install it simply by executing a dnf command.

    [root@rhel-8-lamp ~]# dnf install -y php php-mysqlnd php-mbstring php-pdo php-gd ... Installed: php-7.2.11-1.module+el8+2561+1aca3413.x86_64 php-gd-7.2.11-1.module+el8+2561+1aca3413.x86_64 php-mbstring-7.2.11-1.module+el8+2561+1aca3413.x86_64 php-mysqlnd-7.2.11-1.module+el8+2561+1aca3413.x86_64 php-pdo-7.2.11-1.module+el8+2561+1aca3413.x86_64 php-fpm-7.2.11-1.module+el8+2561+1aca3413.x86_64 gd-2.2.5-6.el8.x86_64 jbigkit-libs-2.1-14.el8.x86_64 libX11-1.6.7-1.el8.x86_64 libX11-common-1.6.7-1.el8.noarch libXau-1.0.8-13.el8.x86_64 libXpm-3.5.12-7.el8.x86_64 libjpeg-turbo-1.5.3-7.el8.x86_64 libtiff-4.0.9-13.el8.x86_64 libwebp-1.0.0-1.el8.x86_64 libxcb-1.13-5.el8.x86_64 nginx-filesystem-1:1.14.1-8.module+el8+2505+fe936cef.noarch php-cli-7.2.11-1.module+el8+2561+1aca3413.x86_64 php-common-7.2.11-1.module+el8+2561+1aca3413.x86_64 dejavu-fonts-common-2.35-6.el8.noarch dejavu-sans-fonts-2.35-6.el8.noarch fontconfig-2.13.1-3.el8.x86_64 fontpackages-filesystem-1.44-22.el8.noarch Complete!

    During installation, PHP created necessary configuration file in Apache configuration directory. Therefore, we have to restart httpd.service to integrate PHP with Apache HTTP Server.

    [root@rhel-8-lamp ~]# systemctl restart httpd.service

    Create a PHP file to verify PHP installation and its integration with Apache HTTP Service.

    [root@rhel-8-lamp ~]# echo "<?php phpinfo() ?>" > /var/www/html/info.php

    Browse URL in a client's browser.


    We have successfully installed LAMP Stack on Red Hat Enterprise Linux (RHEL) 8.

    No comments:

    Post a comment