How to Install a LEMP Server on Rocky Linux

Rocky Linux LEMP tutorial

Hey there! Some links on this page may be affiliate links which means that, if you choose to make a purchase, I may earn a small commission at no extra cost to you. I greatly appreciate your support!

In this tutorial, learn how to set up a LEMP (Linux, Nginx, MariaDB, and PHP) server on Rocky Linux.

Prerequisites:

Please note that a complete video tutorial is available at the end of this tutorial.

1. Update Rocky Linux

It’s always good practice to update your system before installing any new packages.

dnf upgrade

2. Install Nginx Web Server

Install the Nginx web server, start it up, and enable it to automatically startup at boot with the following commands.

dnf install nginx 
systemctl start nginx
systemctl status nginx
systemctl enable nginx

At this point, you can go to the IP address of your web browser and see the default Nginx landing page for Rocky Linux.

Nginx default landing page on Rocky Linux

The source for this page exists at /usr/share/nginx/html/index.html.

3. Install PHP

While you can install any version of PHP that Rocky Linux supports, this tutorial will show you how to install PHP 7.4.

dnf module list php 
dnf module enable php:7.4
dnf install php

Check the version of PHP that is installed.

php -v

Change the user and group associated with PHP-FPM (the intermediary between Nginx and PHP) by editing the file at /etc/php-fpm.d/www.conf. These values will probably be apache by default.

user = nginx
Group = nginx

Start up PHP-FPM and enable it to automatically start at system boot.

systemctl start php-fpm 
systemctl status php-fpm
systemctl enable php-fpm
systemctl restart nginx

4. Install MariaDB

Install the database, start it up, and enable it to automatically start at system boom.

dnf install mariadb-server
systemctl start mariadb
systemctl status mariadb
systemctl enable mariadb

Secure the MariaDB installation by setting a root password. Answer Y to all prompts.

mysql_secure_installation

The database command prompt is accessible with this command. Please provide the password that you just created in the previous step.

mysql -u root -p

YouTube video

Next Steps

From here, you can create the website of your choice including WordPress on Rocky Linux.

Facebook
Twitter
Pinterest
LinkedIn
Reddit

Meet Tony

Tony Teaches Tech headshot

With a strong background in computer science and enterprise web development, Tony is determined to demystify the web. Discover why Tony quit his job to pursue this mission. You can join the Tony Teaches Tech community here.

Leave a Reply

Your email address will not be published. Required fields are marked *