LAMP which stands for Linux, Apache, MySQL/MariaDB, PHP/Perl/Python, is a stack model of software components that are used to develop both static and dynamic websites and web applications. It is open-source and the most common way that is widely used to deliver custom web applications.

Linux is the operating system that is used to install the other components. It is preferred due to its flexibility and its ability to offer more configuration options as compared to other Operating systems.

Apache is the Web Server that is used to process HTTP requests and transmits information over the internet. This makes an application accessible to anyone via a simple web URL. Apache is preferred over other web servers for its maturity and feature-rich ecosystem.

MySQL is a cross-platform relational database for storing application data. Data is stored in a structured format in tables. MySQL is robust and suitable for large running and complex sites with lots of users contributed content. MySQL can be swapped with Maria DB which is also an open-source relational database management system, with the difference being it is absolutely free. It is compatible with the other components and can transfer data without complications or data losses.

PHP is the programming language that works with Apache to create dynamic websites. It is preferred because it is designed for efficiency in delivering fast results. PHP can be swapped with Perl or Python programming language.

LAMP stack has some advantages to it including;

  • It is open-source improving its overall performance.
  • It is a mature stack that is easy to stack up.
  • It has large customer support due to its large community.
  • easily customizable by allowing you to change a component with another open-source software

However, LAMP is only available for Linux operating systems and the use of the relational database in LAMP makes it less efficient than other competitors that use Non-relational databases.

This guide will show you how to install LAMP on AlmaLinux 9|RHEL 9|CentOS 9.

Install LAMP on AlmaLinux9 / RHEL9 / CentOS9

Let us first update our system packages.

sudo dnf update -y

consider having a reboot after a successful upgrade.

sudo reboot

Step 1. Install Apache Web Server

To install Apache, use the following command.

sudo dnf install httpd httpd-tools -y

Start and enable Apache service.

sudo systemctl start httpd
sudo systemctl enable httpd

Check the status of Apache to see if it is running.

$ systemctl status httpd
● httpd.service - The Apache HTTP Server
     Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor pre>
     Active: active (running) since Fri 2022-06-10 19:50:28 EAT; 28s ago
       Docs: man:httpd.service(8)
   Main PID: 30328 (httpd)
     Status: "Total requests: 0; Idle/Busy workers 100/0;Requests/sec: 0; Bytes>
      Tasks: 213 (limit: 23440)
     Memory: 25.1M
        CPU: 77ms
     CGroup: /system.slice/httpd.service
             ├─30328 /usr/sbin/httpd -DFOREGROUND
             ├─30329 /usr/sbin/httpd -DFOREGROUND
             ├─30330 /usr/sbin/httpd -DFOREGROUND
             ├─30331 /usr/sbin/httpd -DFOREGROUND
             └─30332 /usr/sbin/httpd -DFOREGROUND
Jul 01 07:33:43 alma9.mylab.io systemd[1]: Starting The Apache HTTP Server...
Jul 01 07:33:44 alma9.mylab.io systemd[1]: Started The Apache HTTP Server.
Jul 01 07:33:44 alma9.mylab.io httpd[13405]: Server configured, listening on: port 80

To access via a browser, we should allow HTTP/S traffic across the firewall.

sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https

Reload the firewall to apply the changes

sudo firewall-cmd --reload

Then proceed to your browser on http://your-ip-address

Step 2. Install MySQL/MariaDB Database Server

You can choose to install either MySQL or MariaDB database servers.

a. Install MySQL

To install MySQL, use the following command.

sudo dnf install mysql-server -y

Start and enable the service

sudo systemctl start mysqld
sudo systemctl enable mysqld

Check the status of the MySQL service.

$ systemctl status mysqld
 mysqld.service - MySQL 8.0 database server
     Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor pr>
     Active: active (running) since Fri 2022-06-10 21:04:41 EAT; 29s ago
   Main PID: 5028 (mysqld)
     Status: "Server is operational"
      Tasks: 38 (limit: 23440)
     Memory: 465.0M
        CPU: 3.451s
     CGroup: /system.slice/mysqld.service
             └─5028 /usr/libexec/mysqld --basedir=/usr
Jul 01 07:36:06 alma9.mylab.io systemd[1]: Starting MySQL 8.0 database server...
Jul 01 07:36:06 alma9.mylab.io mysql-prepare-db-dir[15443]: Initializing MySQL database
Jul 01 07:36:11 alma9.mylab.io systemd[1]: Started MySQL 8.0 database server.

b. Install MariaDB

To install MariaDB use the following command.

sudo dnf remove mysql-server -y
sudo rm -rf /var/lib/mysql
sudo dnf install mariadb-server -y

Start and aenbale MariaDB service.

sudo systemctl start mariadb
sudo systemctl enable mariadb

Check the status of the service with the following command.

$ systemctl status mariadb
 mariadb.service - MariaDB 10.5 database server
     Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor p>
     Active: active (running) since Fri 2022-06-10 20:04:39 EAT; 42s ago
       Docs: man:mariadbd(8)
             https://mariadb.com/kb/en/library/systemd/
   Main PID: 33336 (mariadbd)
     Status: "Taking your SQL requests now..."
      Tasks: 14 (limit: 23440)
     Memory: 73.3M
        CPU: 340ms
     CGroup: /system.slice/mariadb.service
             └─33336 /usr/libexec/mariadbd --basedir=/usr

c. Secure MariaDB/MySQL

Secure MariaDB/MySQL using the MySQL installation script. You can configure it by picking the default options by pressing Enter.

$ sudo mysql_secure_installation
Switch to unix_socket authentication [Y/n] n
Change the root password? [Y/n] y
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y

To login to MariaDB/MySQL, use the following command.

$ mysql -u root -p

To logout use the following command

> exit

Step 3. Install PHP and required modules

To install PHP, use the following command.

sudo dnf install php -y

The syntax for installing additional PHP modules that assess different needs is shown below.

sudo dnf install php-<package name>

In this tutorial, we will install a few additional modules using the following command.

sudo dnf install php-mysqlnd php-gd php-curl php-ftp php-fpm -y

Check the PHP version using the following command.

$ php -v
PHP 8.0.13 (cli) (built: Nov 16 2021 18:07:21) ( NTS gcc x86_64 )
Copyright (c) The PHP Group
Zend Engine v4.0.13, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.13, Copyright (c), by Zend Technologies

Reload the webserver to accept PHP requests.

sudo systemctl restart httpd

Step 4. Test PHP installation

Edit the PHP configuration file using the following command.

sudo vi /var/www/html/info.php

Add the following code.

<?php
phpinfo ();
?>

Save and exit the file.

Go to your browser and access the following web address http://our-ip-address/info.php

Conclusion

This article shows how to install LAMP Stack on AlmaLinux9|RHEL9|CentOS9 systems. It is easy to set up as we have seen and you can then continue to develop dynamic websites with the stack. LAMP is popular and mature with the disadvantage that it is only available in Linux operating systems.

More on RHEL 9 based systems.

LEAVE A REPLY

Please enter your comment!
Please enter your name here