In this tutorial, learn how to set up a LEMP (Linux, Nginx, MariaDB, and PHP) server on Rocky Linux.
Prerequisites:
- Rocky Linux server (need a server? Get $200 free DigitalOcean credits when you use my referral link)
- SSH root or sudo access to the server
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.
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
Next Steps
From here, you can create the website of your choice including WordPress on Rocky Linux.