## Tutorial ##
How To Install LAMP Stack on Rocky Linux 9
Published on May 17 2023 · Updated on May 17 2023
In this article, we'll explain how to install LAMP Stack on Rocky Linux 9. We will install Apache, MariaDB, and PHP and deploy a test website page also we will install SSL certificate using Certbot.
Apache, MySQL/MariaDB, and PHP are composed of packages. It is known as LAMP and installs on the Linux system environment.
Install LAMP Stack on Rocky Linux 9
- Rocky Linux 9 dedicated server or KVM VPS.
- A root user access or normal user with sudo privileges.
1. Keep the server up-to-date:
sudo dnf update -y
2. Install Apache webserver
sudo dnf install httpd -y
Start and enable Apache service using following command:
sudo systemctl start httpd && sudo systemctl enable httpd
In case, you enabled firewalld, configure the ports in the firewall.
sudo firewall-cmd --add-port=80/tcp --permanent
sudo firewall-cmd --add-port=443/tcp --permanent
sudo firewall-cmd --reload
Now, let’s verify the Apache installation. Open browser and test default page.
3. Install MariaDB
First, we need to add MariaDB repo. Create a mariadb.repo file in /etc/yum.repo.d/ directory.
sudo vi /etc/yum.repos.d/mariadb.repo
We need to import the public key used by the package management system. We can import it using following command:
name = MariaDB
baseurl = https://rpm.mariadb.org/10.11/rhel/$releasever/$basearch
gpgkey = https://rpm.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck = 1
Now, run the installation command.
sudo dnf install mariadb-server -y
Start and enable the mariadb.service using following command:
sudo systemctl start mariadb && sudo systemctl enable mariadb
4. Install PHP
First, we need to install EPEL.
sudo dnf install epel-release -y
List available PHP module.
sudo dnf module list php
Next, enable PHP 8.1 using following command:
sudo dnf module install php:8.1
Now, let's install PHP and some PHP packages using following command:
sudo dnf install php php-common php-mysqli php-gd php-cli -y
Verify the PHP installation:
5. Deploy website
We have installed all the necessary packages to deploy the website om the Apache. Now, let's deploy the website.
first create a website root directory.
sudo mkdir -p /var/www/website_name
Note: Replace the website_name to you website name.
Now, change the working directory to newly created website directory.
Create a index.html file using following command:
sudo vi index.html
Copy and paste following conents:
It's a basic HTML code, you can replace it what ever you want.
Save and close
Change the ownership of the directory and files.
sudo chown -R apache:apache /var/www/website_name
Now, let's create a virtual host for our website. Create a file in /etc/apache2/sites-available/ using following command:
sudo vi /etc/httpd/conf/website_name.com.conf
Note: replace website_name.com to your website name.
Add following lines:
ServerName <domain name or server IP>
Options Indexes FollowSymLinks MultiViews
allow from all
- Replace <domain name or server IP> with you domain name or server IP.
- Replace website_name with your domain name or directory name.
Save and exit
Restart the Apache web server to load the new virtual host file.
sudo systemctl restart httpd
6. Install Certbot
Let's secure the website using SSL. We will issue a SSL certificate using Certbot which is free to use. Use following command to install Certbot:
sudo dnf install certbot python3-certbot-apache -y
Obtain a SSL certificate using certbot command. The Nginx plugin will take care of reconfiguring Nginx and reloading the config.
sudo certbot --apache -d hostnextra.com
Note: Replace hostnextra.com to your domain name.
By running certbot first time, you will be prompted to enter an email address and agree to the terms of service.
At this point, we have successfully installed everything needed. Now let's navigate to the browser and access the domain.
Once the certificate installed, test the renewal process, you can do a dry run with Certbot:
The Certbot packages on your system come with a cron job or systemd timer that will renew your certificates automatically before they expire.
sudo certbot renew --dry-run
That's it, navigate to your browser and enter your domain name or server IP.
We've seen how to install LAMP stack on Rocky Linux 9.
We'll explain how to install Maven on Ubuntu 22.04. For this demonstration purpose, we're installing current LTS version JDK 17.
We'll explain you how to install Elasticsearch on Rocky Linux 9. We'll perform CRUD operation using RESTful API. It's a distributed, RESTful and analytics.
We'll explain you how to install Elasticsearch on AlmaLinux 9. We'll perform CRUD operation using RESTful API. It's a distributed, RESTful search and analytics.