LAMP is free, open-source, and one of the most popular development stacks used by developers and hosting companies to host web applications on the internet. LAMP stands for Linux, Apache, MariaDB, and PHP. A LAMP stack is a group of open-source Linux-based web development software that includes Apache web server, MariaDB (or MySQL database server), and PHP.
In this post, we will explain how to install a LAMP stack on Rocky Linux 8.
Step 1 – Install Apache Web Server on Rocky Linux 8
By default, the Apache webserver is included in the Rocky Linux 8 default repo. You can install it by running the following command:
dnf install httpd -y
This command will install the HTTP package along with other necessary dependencies as shown below:
Rocky Linux 8 - AppStream 5.2 MB/s | 8.0 MB 00:01 Rocky Linux 8 - BaseOS 2.0 MB/s | 4.5 MB 00:02 Rocky Linux 8 - Extras 6.8 kB/s | 3.9 kB 00:00 Last metadata expiration check: 0:00:01 ago on Wednesday 04 August 2021 06:48:28 AM UTC. Dependencies resolved. =============================================================================================================================================== Package Architecture Version Repository Size =============================================================================================================================================== Installing: httpd x86_64 2.4.37-39.module+el8.4.0+571+fd70afb1 appstream 1.4 M Installing dependencies: apr x86_64 1.6.3-11.el8.1 appstream 124 k apr-util x86_64 1.6.1-6.el8.1 appstream 104 k httpd-filesystem noarch 2.4.37-39.module+el8.4.0+571+fd70afb1 appstream 37 k httpd-tools x86_64 2.4.37-39.module+el8.4.0+571+fd70afb1 appstream 105 k mod_http2 x86_64 1.15.7-3.module+el8.4.0+553+7a69454b appstream 153 k rocky-logos-httpd noarch 84.5-8.el8 baseos 22 k Installing weak dependencies: apr-util-bdb x86_64 1.6.1-6.el8.1 appstream 23 k apr-util-openssl x86_64 1.6.1-6.el8.1 appstream 26 k Enabling module streams: httpd 2.4 Transaction Summary
After the installation, run the following command to start the Apache service and enable it to start at system reboot.
systemctl start httpd systemctl enable httpd
Next, verify the status of the Apache service using the following command:
systemctl status httpd
You should see the following output:
● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled) Active: active (running) since Wed 2021-08-04 06:49:01 UTC; 12s ago Docs: man:httpd.service(8) Main PID: 24701 (httpd) Status: "Running, listening on: port 80" Tasks: 213 (limit: 11411) Memory: 25.0M CGroup: /system.slice/httpd.service ├─24701 /usr/sbin/httpd -DFOREGROUND ├─24769 /usr/sbin/httpd -DFOREGROUND ├─24770 /usr/sbin/httpd -DFOREGROUND ├─24772 /usr/sbin/httpd -DFOREGROUND └─24773 /usr/sbin/httpd -DFOREGROUND Aug 04 06:49:01 RockyLinux8 systemd[1]: Starting The Apache HTTP Server...
Next, open your web browser and verify the Apache test page using the URL http://your-server-ip. You should see the Apache test page on the following screen:
Step 2 – Install MariaDB Database Server on Rocky Linux 8
Next, you will need to install the MariaDB or MySQL database server in your system. I would recommend installing the MariaDB server due to its numerous enhancements, like high-performance storage engines and backward compatibility with MySQL.
Run the following command to install the MariaDB server:
dnf install mariadb-server -y
After installing MariaDB, start the MariaDB service and enable it to start at system reboot:
systemctl start mariadb systemctl enable mariadb
Run the following command to verify that the MariaDB daemon is running:
systemctl status mariadb
Next, I would recommend running the mysql_secure_installation script to secure the MariaDB installation.
You can run it using the following command:
mysql_secure_installation
You will then be asked whether to set a MariaDB root password, remove anonymous users, disallow root login, and remove the test database, as shown below:
Enter current password for root (enter for none): Set root password? [Y/n] Y New password: Re-enter new password: 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
Step 3 – Install PHP on Rocky Linux 8
Next, you will need to install PHP (PHP Hypertext Preprocessor) in your system. By default, Rocky Linux AppStream repo provides multiple versions of PHP.
You can check all available PHP versions using the following command:
dnf module list php
You should see the following output:
Last metadata expiration check: 0:03:46 ago on Wednesday 04 August 2021 06:48:28 AM UTC. Rocky Linux 8 - AppStream Name Stream Profiles Summary php 7.2 [d] common [d], devel, minimal PHP scripting language php 7.3 common [d], devel, minimal PHP scripting language php 7.4 common [d], devel, minimal PHP scripting language
The default PHP version is set to PHP 7.2. If you want to install the latest PHP 7.4, you will need to reset the default PHP steams.
Run the following command to reset the default PHP:
dnf module reset php
Next, enable the PHP 7.4 version using the following command:
dnf module enable php:7.4
Next, install PHP 7.4 with other extensions using the following command:
dnf install php php-cli php-curl php-zip php-mysqli -y
Once PHP is installed, verify the installed version of PHP with the following command:
php -v
You should see the following command:
PHP 7.4.6 (cli) (built: May 12 2020 08:09:15) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies with Zend OPcache v7.4.6, Copyright (c), by Zend Technologies
You can also test the PHP version through the web browser.
To do so, create an info.php file:
nano /var/www/html/info.php
Add the following lines:
<?php phpinfo(); ?>
Save and close the file, then restart the Apache service to apply the changes:
systemctl restart httpd
Now, open your web browser and access the info.php page using the URL http://your-server-ip/info.php. You should see the PHP version on the following screen:
Conclusion
In the above guide, you learned how to install the LAMP stack on Rocky Linux 8. You should now have enough understanding of LAMP to install it for yourself and start hosting your website on the Internet using the LAMP stack; try it on your Atlantic.Net virtual private server!