Install WordPress on Rocky Linux 9 with Nginx
Rocky Linux 9 is a powerful operating system designed for servers, particularly in the realm of web hosting and server management. In this tutorial, we’ll walk through the process of installing WordPress on Rocky Linux 9 using the Nginx web server. WordPress is a popular content management system (CMS) that allows users to create and manage websites with ease. By combining Rocky Linux’s stability and security with the versatility of WordPress and Nginx, you can create a robust and dynamic web presence for your projects or business. Let’s dive into the steps to set up WordPress on Rocky Linux 9 with Nginx.
Tutorial Environment
In this tutorial, we will work with the following server, operating system, and software:
- Vultr Cloud Server: 1 CPU, 1 GB RAM, 32 GB Storage
- Operating System: Rocky Linux 9
- Domain: aminlabs.my.id
- SSL: Let’s Encrypt
- Web Server: Nginx v1.20
- PHP: PHP v8.2
- Database: MariaDB v10.5
- WordPress: WordPress v6.4.3
Note: Register here to get $100 free credit from Vultr.
Step 1: Update system packages
Connect to your server and ensure your system packages are up-to-date:
1 | dnf update |
Note: This tutorial uses the root user.
Step 2: Install Nginx web server
Execute the following command to install the Nginx web server:
1 | dnf install nginx |
After the installation is complete, start the Nginx service and enable it to start on boot:
1 2 | systemctl start nginx systemctl enable nginx |
You can verify the Nginx service status to ensure it’s running without any issues:
1 | systemctl status nginx |
Open HTTP and HTTPS ports in firewall, execute the following commands:
1 2 3 | firewall-cmd --permanent --add-service=http firewall-cmd --permanent --add-service=https firewall-cmd --reload |
Step 3: Install MariaDB database
Install MariaDB server using the following command:
1 | dnf install mariadb-server |
Start the MariaDB service and enable it to start on boot:
1 2 | systemctl start mariadb systemctl enable mariadb |
Step 4: Create a Database
Log in to MariaDB server:
1 | mysql |
Create a MariaDB database for WordPress:
1 2 3 4 | CREATE DATABASE aminlabs; GRANT ALL PRIVILEGES ON aminlabs.* TO 'aminlabs'@'localhost' IDENTIFIED BY 'secretpassword'; FLUSH PRIVILEGES; exit |
Step 5: Install PHP 8.2
To install PHP 8.2 on Rocky Linux 9, you need to add the EPEL repository and the REMI repository to your system. These repositories provide additional packages, including newer versions of PHP that are not available in the default Rocky Linux repositories.
EPEL (Extra Packages for Enterprise Linux) repository provides additional packages for CentOS and its derivatives like Rocky Linux. Install the EPEL repository using the following command:
1 | dnf install epel-release |
REMI repository provides updated versions of various software packages, including PHP, that are not available in the default repositories. Install the REMI repository by executing the following commands:
1 | dnf install https://rpms.remirepo.net/enterprise/remi-release-9.rpm |
Once you have installed the REMI repository, enable the PHP 8.2 repository:
1 | dnf module enable php:remi-8.2 |
Now, you can install PHP 8.2 and the required PHP modules:
1 | dnf install php82-php-fpm php82-php-cli php82-php-curl php82-php-mysqlnd php82-php-gd php82-php-opcache php82-php-zip php82-php-intl php82-php-common php82-php-bcmath php82-php-imagick php82-php-xmlrpc php82-php-json php82-php-readline php82-php-memcached php82-php-redis php82-php-mbstring php82-php-apcu php82-php-xml php82-php-dom php82-php-redis php82-php-memcached php82-php-memcache |
Create a symbolic link for php82
:
1 | ln -s /usr/bin/php82 /usr/bin/php |
Open PHP-FPM pool configuration file:
1 | nano /etc/opt/remi/php82/php-fpm.d/www.conf |
Adjust the configuration as below:
1 2 3 4 5 | user = nginx group = nginx listen.owner = nginx listen.group = nginx ;listen.acl_users = apache |
Start the PHP-FPM service and enable it to start on boot:
1 2 3 | systemctl enable php82-php-fpm systemctl start php82-php-fpm systemctl status php82-php-fpm |
Step 6: Configure Server Block
Create the directory for aminlabs.my.id
:
1 | mkdir /var/www/aminlabs.my.id |
Create a server block configuration for the domain aminlabs.my.id
:
1 | nano /etc/nginx/conf.d/aminlabs.my.id.conf |
Insert the following virtual host configuration:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | server { listen 80; server_name www.aminlabs.my.id aminlabs.my.id; root /var/www/aminlabs.my.id; index index.php; location / { try_files $uri $uri/ /index.php?$args; } location ~ \.php$ { try_files $fastcgi_script_name =404; include fastcgi_params; fastcgi_pass unix:/var/opt/remi/php82/run/php-fpm/www.sock; fastcgi_index index.php; fastcgi_param DOCUMENT_ROOT $realpath_root; fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; } access_log /var/log/nginx/aminlabs.my.id_access.log; error_log /var/log/nginx/aminlabs.my.id_error.log; } |
Restart the Nginx service to reload configuration:
1 | systemctl restart nginx |
Step 7: Install SSL from Let’s Encrypt
Let’s Encrypt is a free, automated, and open certificate authority that provides digital certificates for enabling HTTPS (SSL/TLS) on websites. It was launched in 2015 by the Internet Security Research Group (ISRG) with the aim of making it easier for website owners to secure their websites with HTTPS. Let’s Encrypt certificates are trusted by all major browsers and are valid for 90 days, after which they can be renewed automatically.
Install Certbot and the Nginx web server plugin:
1 | dnf install certbot python3-certbot-nginx |
Request an SSL certificate for aminlabs.my.id
and www.aminlabs.my.id
. The email address is used to send notifications when the SSL certificate is about to expire.
1 | certbot --non-interactive -m admin@aminlabs.my.id --agree-tos --no-eff-email --nginx -d aminlabs.my.id -d www.aminlabs.my.id --redirect |
Example message displayed when the SSL certificate request is successful:
1 2 3 4 5 6 7 8 9 10 11 12 | Account registered. Requesting a certificate for aminlabs.my.id and www.aminlabs.my.id Successfully received certificate. Certificate is saved at: /etc/letsencrypt/live/aminlabs.my.id/fullchain.pem Key is saved at: /etc/letsencrypt/live/aminlabs.my.id/privkey.pem This certificate expires on 2024-05-03. These files will be updated when the certificate renews. Certbot has set up a scheduled task to automatically renew this certificate in the background.Deploying certificate Successfully deployed certificate for aminlabs.my.id to /etc/httpd/conf.d/aminlabs.my.id-le-ssl.conf Successfully deployed certificate for www.aminlabs.my.id to /etc/httpd/conf.d/aminlabs.my.id-le-ssl.conf Congratulations! You have successfully enabled HTTPS on https://aminlabs.my.id and https://www.aminlabs.my.id |
Step 8: Install WordPress via WP-CLI
WP-CLI (WordPress Command Line Interface) is a powerful tool for managing WordPress installations from the command line. It provides a convenient and efficient way to perform various tasks such as installing, updating, and managing WordPress sites without needing to use a web browser.
With WP-CLI, you can automate WordPress tasks, script complex operations, and interact with your WordPress site’s database directly from the command line interface. This makes it an indispensable tool for developers, system administrators, and anyone who manages multiple WordPress sites.
Begin by installing WP-CLI on your server. You can download the Phar file and make it executable for global use:
1 2 | wget https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar -O /usr/local/bin/wp chmod +x /usr/local/bin/wp |
Navigate to document root directory:
1 | cd /var/www/aminlabs.my.id |
Download the latest WordPress core files using WP-CLI:
1 | wp core download |
Generate the wp-config.php
file using WP-CLI and provide the necessary database information:
1 2 3 4 5 | wp config create \ --dbname="aminlabs" \ --dbuser="aminlabs" \ --dbpass="secretpassword" \ --dbhost="localhost" |
Install WordPress and create an admin account:
1 2 3 4 5 6 | wp core install \ --url="https://www.aminlabs.my.id" \ --title="AminLabs Blog" \ --admin_user="admin" \ --admin_password="secretpassword" \ |
The message displayed when WordPress installation is successful:
1 | Success: WordPress installed successfully. |
Change the user and group of the WordPress files to the user and group of the Nginx web server:
1 | chown -R nginx:nginx /var/www/aminlabs.my.id |
The WordPress installation process has been completed. Browse the domain to try the installation result.
If you found this article helpful and would like to support my work, consider making a donation through PayPal. Your support helps me continue creating useful content and tutorials. Thank you!
Donate via PayPal: https://paypal.me/musaamin