How to Install LAMP Server on RHEL, CentOS, Rocky & AlmaLinux

A LAMP stack is a collection of four different software (Linux, Apache, MySQL, and PHP) that programmers or web developers use to create and deploy websites or applications.

This tutorial will concentrate on how to install and configure the famous LAMP stack with PhpMyAdmin on the last release of RHEL and RHEL-based distributions such as CentOS, Oracle Linux, Rocky, and AlmaLinux.

Requirements

Depending on the used distribution, use the following links to perform a minimal system installation, using a static IP Address for network configuration.

Step 1: Install Apache Web Server

1. After performing a minimal system installation and configuring your server network interface with a Static IP Address, go ahead and install Apache (httpd) service binary package provided from official repositories using the following yum command.

# yum install httpd
Install Apache in Linux
Install Apache on Linux

2. After finishing the Apache installation, use the following commands to manage Apache daemon since RHEL and CentOS both migrated their init scripts from SysV to SystemdWhy was init Replaced with Systemd in Linux?.

# systemctl start httpd
# systemctl enable httpd
# systemctl status httpd
Manage Apache in Linux
Manage Apache in Linux

3. On the next step, make sure to allow access to Apache by opening ports 80 and 443 on Firewall using firewall-cmd, which is the default command to manage Firewalld through daemon.

# firewall-cmd --add-service=http
# firewall-cmd --add-service=https
# systemctl restart firewalld
NOTE: Make notice that using this rule will lose its effect after a system reboot or firewalld service restart because it opens on-fly rules, which are not applied permanently.

To apply consistency iptables rules on the firewall using the --permanent option and restart the firewalld service to take effect.

# firewall-cmd --permanent --add-service=http
# firewall-cmd --permanent --add-service=https
# systemctl restart firewalld
Open Apache Ports in Firewalld
Open Apache Ports in Firewalld

Some important Firewalld commands to manage the firewall as presented below:

# firewall-cmd --state
# firewall-cmd --list-all
# firewall-cmd --list-interfaces
# firewall-cmd --get-service
# firewall-cmd --query-service service_name
# firewall-cmd --add-port=80/tcp

4. To verify Apache functionality open a remote browser and type your server IP Address using HTTP protocol on the URL, and a default page should appear like in the screenshot below.

http://server_IP
Verify Apache in Linux
Verify Apache in Linux

5. For now, the Apache DocumentRoot path it’s set to /var/www/html system path, which by default doesn’t provide any index file. If you want to see a directory list of your DocumentRoot path.

Open the Apache welcome configuration file and set the Indexes statement from to + on LocationMatch directive, using the below screenshot as an example.

# vi /etc/httpd/conf.d/welcome.conf
Configure Apache Welcome Page
Configure Apache Welcome Page

6. After making changes, close the file, restart the Apache service to reflect changes, and reload your browser page to see the final result.

# systemctl restart httpd
Apache Directory Listing
Apache Directory Listing

Step 2: Install PHP Support for Apache

7. Before installing PHP dynamic language support for Apache, get a full list of available PHP modules and extensions using the following command.

# yum search php
List PHP Modules
List PHP Modules

8. Depending on what type of applications you want to use, install the required PHP modules from the above list, but for a basic MySQL/MariaDB support in PHP and PhpMyAdmin you need to install the following modules.

# yum install php php-mysql php-pdo php-gd php-mbstring
Install PHP Modules
Install PHP Modules

9. To get a full information list on PHP from your browser, create an info.php file on Apache Document Root using the following command, restart the httpd service, and direct your browser to the http://server_IP/info.php address.

# echo "<?php phpinfo(); ?>" > /var/www/html/info.php
# systemctl restart httpd
List PHP Information
List PHP Information

10. If you get an error on PHP Date and Timezone, open the php.ini configuration file, search, and uncomment date.timezone statement, append your physical location, and restart the Apache daemon.

# vi /etc/php.ini

Locate and change date.timezone line to look like this, using PHP Supported Timezones list.

date.timezone = Continent/City
Set PHP Timezone
Set PHP Timezone

Step 3: Install and Configure MariaDB Database

11. The RHEL distribution switched from MySQL to MariaDB for its default database management system. To install the MariaDB database use the following command.

# yum install mariadb-server mariadb
Install MariaDB in Linux
Install MariaDB on Linux

12. After the MariaDB package is installed, start the database daemon and use the mysql_secure_installation script to secure the database (set a root password, disable remote login from the root, remove the test database, and remove anonymous users).

# systemctl start mariadb
# systemctl enable mariadb
# systemctl status mariadb
# mysql_secure_installation
Manage MariaDB Service
Manage MariaDB Service
Secure MariaDB in Linux
Secure MariaDB in Linux

13. To test database functionality login to MariaDB using its root account and exit using a quit statement.

mysql -u root -p
MariaDB > show databases;
MariaDB > quit
Connect MariaDB in Linux
Connect MariaDB to Linux

Step 4: Install PhpMyAdmin to Manage MySQL

14. By default official repositories don’t provide any binary package for PhpMyAdmin Web Interface. If you are uncomfortable using the MySQL command line to manage your database you can install the PhpMyAdmin package by enabling the remi repository using the following command.

# yum install -y https://rpms.remirepo.net/enterprise/remi-release-9.rpm  [On CentOS/RHEL 8]
# yum install -y https://rpms.remirepo.net/enterprise/remi-release-8.rpm  [On CentOS/RHEL 8]
# yum install -y https://rpms.remirepo.net/enterprise/remi-release-7.rpm  [On CentOS/RHEL 7]

After enabling the remi repository, next install PhpMyAdmin.

# yum install phpmyadmin
Install PhpMyAdmin in Linux
Install PhpMyAdmin on Linux

15. Next configure PhpMyAdmin to allow connections from remote hosts by editing phpmyadmin.conf file, located on the Apache conf.d directory, commenting on the following lines.

# vi /etc/httpd/conf.d/phpMyAdmin.conf

Add the “Require all granted” line under the “Require local” line as shown.

<Directory /usr/share/phpMyAdmin/>
   AddDefaultCharset UTF-8
   Require local
   Require all granted
</Directory>
Allow Remote PhpMyAdmin Access
Allow Remote PhpMyAdmin Access

16. To be able to log in to the PhpMyAdmin Web interface, restart the Apache Web service and direct your browser to the URL address.

# systemctl restart httpd

http://server_IP/phpmyadmin/
PhpMyAdmin Dashboard
PhpMyAdmin Dashboard

Step 5: Enable LAMP System-Wide in Linux

17. If you need MariaDB and Apache services to be automatically started after reboot issue the following commands to enable them system-wide.

# systemctl enable mariadb
# systemctl enable httpd

That’s all it takes for a basic LAMP installation on RHEL-based distributions. The next series of articles related to the LAMP stack will discuss how to create Virtual Hosts, generate SSL Certificates and Keys, and add SSL transaction support for Apache HTTP Server.

Matei Cezar
I'am a computer addicted guy, a fan of open source and linux based system software, have about 4 years experience with Linux distributions desktop, servers and bash scripting.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

31 thoughts on “How to Install LAMP Server on RHEL, CentOS, Rocky & AlmaLinux”

  1. Hi
    One more thing to note:

    rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm
    [root@centos yum-root-bB6l9i]# pwd
    /var/tmp/yum-root-bB6l9i

    //marsk

    Reply
  2. Typo ‘LocationMach’ please change ‘LocationMatch’
    and ‘nano /etc/httpd/conf.d/phpmyadmin.conf’ change to ‘nano /etc/httpd/conf.d/phpMyAdmin.conf’

    New Version

    Reply
    • @Lester,
      Do this way…

      # wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm
      # rpm -Uvh rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm
      
      Reply
    • It’s really late to answer this but I think I would let you know.

      # yum install http://ftp.tu-chemnitz.de/pub/linux/dag/redhat/el7/en/x86_64/rpmforge/RPMS/rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm

      You can get past right this way.

      Reply
  3. @sahadev: Check /etc/httpd/conf.d/phpmyadmin.conf file and verify your IP/netmask
    ##############

    Order Deny,Allow
    Deny from all
    Allow from 10.0.0.0/24 ## Use your IP/Network CDIR
    Require all granted

    Reply
      • @Israrul,

        How to configure PhpMyAdmin to allow access to specific IP address.

        Open /etc/httpd/conf.d/phpMyAdmin.conf file and edit Require ip& Allow from lines as shown in the following example.

        Here is what phpMyAdmin.conf will look like with the added access rules.

        <Directory /usr/share/phpMyAdmin/>
        
        <IfModule mod_authz_core.c>
        # Apache 2.4
        <RequireAny>
        Require ip 127.0.0.1
        Require ip ::1
        # Example office IP
        Require ip 192.168.0.100
        </RequireAny>
        
        </IfModule>
        <IfModule !mod_authz_core.c>
        # Apache 2.2
        Order Deny,Allow
        Deny from All
        Allow from 127.0.0.1
        Allow from ::1
        # Example home IP
        Allow from 192.168.0.100
        </IfModule>
        
        </Directory>
        <Directory /usr/share/phpMyAdmin/setup/>
        <IfModule mod_authz_core.c>
        # Apache 2.4
        <RequireAny>
        Require ip 127.0.0.1
        Require ip ::1
        # Example home IP
        Require ip 192.168.0.100
        </RequireAny>
        
        </IfModule>
        <IfModule !mod_authz_core.c>
        # Apache 2.2
        Order Deny,Allow
        Deny from All
        Allow from 127.0.0.1
        Allow from ::1
        # Example home IP
        Allow from 192.168.0.100
        </IfModule>
        </Directory>
        
        Reply
  4. hi,
    plz guide me how to configure phpmyadmin bcause i am not accessing that and i m receving this nessages

    Forbidden

    You don’t have permission to access /phpmyadmin on this server.

    Apache/2.2.15 (CentOS) Server at 10.0.0.80 Port 80

    Reply
  5. Your installation instructions are great! But I am having issues accessing phpMyAdmin from a remote computer, even adding in the internal IP address of the client machine.

    Reply
    • Hi.
      Thanks a lot!
      Add your network between

      /etc/httpd/conf.d/phpMyAdmin.conf
      15 Require ip 127.0.0.1
      16 Require ip 192.168.0.
      17 Require ip ::1
      18

      Reply
  6. From an install today (2014/07/24) the phpmyadmin.conf file name has been re-cased to:

    phpMyAdmin.conf

    So the location is:

    /etc/httpd/conf.d/phpMyAdmin.conf

    Reply
  7. Yes …you are right…I think they have removed phpmyadmin from rpmforge repositories. A few days ago the packages was there and working. Remove rpmforge from your system and install phpMyAdmin from sources:

    yum remove rpmforge-release
    wget http://downloads.sourceforge.net/project/phpmyadmin/phpMyAdmin/4.2.6/phpMyAdmin-4.2.6-english.tar.gz
    tar xfz phpMyAdmin-4.2.6-english.tar.gz
    mv phpMyAdmin-4.2.6-english/ phpmyadmin
    cp -r phpmyadmin/ /usr/share/
    nano /etc/httpd/conf.d/phpmyadmin.conf

    Here add this lines:

    ##############

    Order Deny,Allow
    Deny from all
    Allow from 192.168.1.0/24 ## Use your IP/Network CDIR
    Require all granted

    Alias /phpmyadmin /usr/share/phpmyadmin
    Alias /phpMyAdmin /usr/share/phpmyadmin
    Alias /mysqladmin /usr/share/phpmyadmin
    ###############

    systemctl restart httpd.service

    cp /usr/share/phpmyadmin/config.sample.inc.php /usr/share/phpmyadmin/config.inc.php

    nano /usr/share/phpmyadmin/config.inc.php

    Add blowfish pass as explained above (http://www.question-defense.com/tools/phpmyadmin-blowfish-secret-generator) and you’re ready!

    Reply

Got something to say? Join the discussion.

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.