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 like Apache or Nginx. Whereas to save data and support PHP based CMS; Mysql and PHP are required. In today’s world, where hundreds of websites run on CMS like WordPress, you can easily find the LAMP setup on most hosting services preinstalled. So, no hassle or inconvenience with the controls at all. In addition, WHM Cpanel type control panels make our life easier.
Still, if you are already a Linux user and want to set up your own LAMP server from scratch on a VPS or Cloud hosting platform using Rocky Linux, here is the tutorial to help you out.
LAMP – Apache, MySQL & PHP installation on Rocky Linux 8 server
The steps and commands given here to configure the LAMP server on Rocky Linux can also be used for AlmaLinux, CentOS, and RHEL 8 Linux.
1. Make sure your server is up to date
Before running an install command, you must first make sure that your system is up to date. And for that just run:
sudo dnf update
2. Install the Apache web server on Rocky Linux 8
So, after the update, the first thing we are going to install and configure is the popular Apache web server. It is also very easy to manage and use. In addition, the packages to configure it are already available in the base Rocky Linux repository, so just run:
sudo dnf install httpd httpd-tools
3. Activate and start Apache
The next step is to start the web server services and have them run automatically when the system starts. This will ensure that we don’t need to start Apache manually after every server restart.
sudo systemctl start httpd
sudo systemctl enable httpd
To confirm that everything is working as it should, you can check the status-
sudo systemctl status httpd
4. Allow HTTP service or port 80 in FireWall
By default, you will not be able to access your web server outside of your Rocky Linux 8 server using another system. For this, we must open ports 80 and 443 in the firewall of our servers.
To note: If you are using a cloud service, open ports 80 and 443 in its dedicated firewall protecting your instance.
While on the 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 the firewall to apply the changes
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 it. This will connect to the default page of the Apache web server hosted on Rocky Linux 8.
5. Install MySQL or MariaDB
Then it is about setting up a medium on which we can store the data of our website, and for this we use database systems. The most common is Oracle’s MySQL or its MariaDB fork.
Both work the same, you can choose which one you want.
Install command for MySQL
sudo dnf install mysql-server mysql
sudo dnf install mariadb-server mariadb -y
Command to start and activate MySQL and MariaDB services
sudo systemctl start mysql sudo systemctl enable mysql
To check the status:
sudo systemctl status mysql
sudo systemctl start mariadb sudo systemctl enable mariadb
sudo systemctl status mariadb
Secure installation of MySQL / MariaDB
Well, as we are the ones who install and manage our database manually and not a hosting service, so it is our responsibility to keep it secure. Therefore, for this we can use the command that will secure it by assigning a password and removing the demo database and restricting its access.
A text-based wizard will ask you to set a root password for MySQL or MariaDB as well as delete empty databases, restrict remote access except localhost, delete anonymous users, etc.
6. Install PHP on the Rocky Linux 8 server
PHP is a popular scripting language that powers dynamic content for millions of websites and applications. Therefore, if you are planning to install a web CMS like WordPress, you need to configure PHP on your Rocky Linux server.
PHP 7.2 / 7.3 / 7.4
Well, let’s first check what versions of PHP are available in the Rocky Linux core repository.
sudo dnf moudle list php
sudo dnf module reset php
Now activate the PHP version you want to install, for example here we install the latest PHP 7.4 available.
sudo dnf module enable php:7.4
Likewise, you can activate some old ones if needed to install.
(optional) While people who want to install PHP 8.0, need to add the Remi Repo.
1. Add the Remi repository
sudo dnf install http://rpms.remirepo.net/enterprise/remi-release-8.rpm
2. Run the system update
sudo dnf update
3. Activate the PHP 8.0 version available for installation
sudo dnf module reset php sudo dnf module enable php:remi-8.0
Now install PHP
sudo dnf install php php-common php-opcache php-mcrypt php-cli php-gd php-curl php-mysqlnd
To get better performance for various applications using PHP, we can start (if we haven’t already) and enable PHP-FPM (FastCGI Process Manager) using the commands below:
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 the active PHP module and other things by calling its configuration details in the browser, here is how to do it.
sudo nano /var/www/html/info.php
Add the following line in the info.php file that we created using the above command:
Save the file by pressing Ctrl + X keys, after this guy- Yes, and press the Enter key.
Now open your browser and enter the IP address of your server as well as the info.php file name, which we created above:
This way we can set up a LAMP-Apache web server, MySQL and PHP database on Rocky Linux 8. Although the steps are very simple, in case you have a problem, the comments section is yours …