How to Install LAMP on Rocky Linux 8 Server

LAMP is a stack of software- Apache, MySQL, and PHP installed on Linux operating systems such as Rocky Linux 8 server, AlmaLinux, CentOS, Ubuntu, etc.

To run a website on any server we need to install a web server platform such as Apache or Nginx. Whereas to save data and support PHP-based CMS; Mysql, and PHP are needed. In today’s world, where hundreds of websites are running on CMS like WordPress you will easily find LAMP setup on most of the hosting services- pre-installed. Thus, no hassle or messing with commands at all. Moreover, WHM Cpanel-like control panels make our life further easier.

Nevertheless, if you are already a user of Linux and want to set up your own LAMP server from scratch on some VPS or Cloud hosting platform using Rocky Linux then here is the tutorial to assist you.

LAMP – Apache, MySQL & PHP installation on Rocky Linux 8 server

The steps and commands given here to set up the LAMP server on Rocky Linux can be used for AlmaLinux, CentOS, and RHEL 8 Linux as well.

1. Make sure your server is up to date

The first you have to ensure before running any installation command is your system is up to date. And for that simply run:

sudo dnf update

 

2. Install Apache web server on Rocky Linux 8

So, after updating the first thing we will install and set up is the popular Apache webserver. It is very easy to manage and use as well. Moreover, the packages to set it up are already available in the base repository of Rocky Linux, hence simply run:

sudo dnf install httpd httpd-tools

 

3. Enable and start Apache

The next, step is to start the webserver services and also make it run automatically with system boot. This will make sure we don’t need to start the Apache manually after every server reboot.

Start

sudo systemctl start httpd

Enable 

sudo systemctl enable httpd

To confirm everything is working as it must be, you can check the status-

sudo systemctl status httpd

 

4. Allow HTTP service or port 80 in FireWall

By default, you won’t be able to access your web server outside your Rocky Linux 8 server using some other system. For that, we have to open ports 80 and 443 in our servers firewall.

Note: if you are using some cloud service then open the 80 & 443 ports in its dedicated firewall protecting your instance.

Whereas, on server

Open port 80 or http:

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

Open port 443 or https:

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

Reload firewall to make changes into effect

sudo firewall-cmd --reload

Once the above things are done, open any system browser that can access your Server’s IP address and point it to that. This will connect to the Apache webserver’s default page hosted on Rocky Linux 8.

http://your-server-ipadress

 

5. Install MySQL or MariaDB

Next is to set up a medium where we can store our website data, and for that, we use Database systems. The most common one is Oracle’s MySQL or its fork MariaDB.

Both work the same, you can choose the one as per your choice.

Installation command for MySQL

sudo dnf install mysql-server mysql

or

For MariaDB

sudo dnf install mariadb-server mariadb -y

Command to Start & Enable MySQL and MariaDB services

For MySQL:

sudo systemctl start mysqld
sudo systemctl enable mysqld

To check status:

sudo systemctl status mysqld

For MariaDB

sudo systemctl start mariadb
sudo systemctl enable mariadb
sudo systemctl status mariadb

 

Secure MySQL/MariaDB installation

Well, as we are the one who is installing and managing our database manually not some hosting service, thus it is our responsibility to secure it. Hence, for that, we can use the command that will secure it by assigning a password and removing the demo database and limiting its access.

mysql_secure_installation

A text-based wizard will ask you to set a root password for MySQL or MariaDB along with removing empty databases, restricting remote access except for localhost, removing anonymous users, and more… Thus, just follow it.

 

6. Install PHP on Rocky Linux 8 server

PHP is a popular scripting language that powers the dynamic content of millions of websites and apps, therefore, if you are planning to install web CMS like WordPress, then you have to set up PHP on your Rocky Linux server.

PHP 7.2/7.3/7.4

Well, let’s first check what are the versions of PHP available in the base repo of Rocky Linux.

sudo dnf moudle list php
sudo dnf module reset php

Now, enable the PHP version you want to install, for example here we are installing the latest available PHP 7.4.

sudo dnf module enable php:7.4

In the same way, you can enable some old ones if required to install.

PHP  8.0

(optional) Whereas the people who want to install PHP  8.0, need to add the Remi Repo.

1. Add Remi Repository 

sudo dnf install http://rpms.remirepo.net/enterprise/remi-release-8.rpm

2. Run system update

sudo dnf update

3. Enable available PHP 8.0 version to install

sudo dnf module reset php 
sudo dnf module enable php:remi-8.0

 

Enable PHP module in Rocky Linux to install

Now, install PHP

sudo dnf install php php-common php-opcache php-cli php-gd php-curl php-mysqlnd

To get better performance for various applications using PHP, we can start (if not already) and enable PHP-FPM (FastCGI Process Manager) using the below commands:

sudo systemctl start php-fpm
sudo systemctl enable php-fpm

 

 

7. To check Rocky Linux LAMP stack PHP in the browser

We have already installed Apache, MySQL, and PHP on our Rocky Linux 8, If you want you can check PHP active module and other things by calling its configuration detail in the browser, here is the way.

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

Add the following line in the info.php file we have created using the above command:

<?php
phpinfo ();
?>

Save the file by pressing Ctrl+X keys, after that type- Y, and hit the Enter key.

Now, open your browser and type your server IP address along with file name info.php, we have created above:

http://your-server-ipaddress/info.php

 

8. Install phpMYAdmin

To manager Database graphically, you can install PHP based phpMyadmin manager, here is the article for that- How to install phpMyAdmin on Rocky Linux 8 with Apache

 

ending note:

In this way, we can set up a webserver LAMP- Apache, MySQL database, and PHP on Rocky Linux 8. Although the steps are very simple, in case you are facing some problem, the comment section is all yours…

 

 

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.