Install WordPress on Rocky Linux 9 with Apache
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 Apache 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 Apache, 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 Apache.
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: Apache v2.4.57
- 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 Apache web server
Execute the following command to install the Apache web server:
1 | dnf install httpd |
After the installation is complete, start the Apache service and enable it to start on boot:
1 2 | systemctl start httpd systemctl enable httpd |
You can verify the Apache service status to ensure itâs running without any issues:
1 | systemctl status httpd |
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: Configure Virtual Host
Create the directory for aminlabs.my.id
:
1 | mkdir /var/www/aminlabs.my.id |
Create a virtual host configuration for the domain aminlabs.my.id
:
1 | nano /etc/httpd/conf.d/aminlabs.my.id.conf |
Insert the following virtual host configuration:
1 2 3 4 5 6 7 8 9 10 11 12 | <VirtualHost *:80> ServerName www.aminlabs.my.id ServerAlias aminlabs.my.id DocumentRoot /var/www/aminlabs.my.id <Directory /var/www/aminlabs.my.id> Options -Indexes +FollowSymLinks +MultiViews AllowOverride All Require all granted </Directory> ErrorLog /var/log/httpd/aminlabs.my.id_error.log CustomLog /var/log/httpd/aminlabs.my.id_access.log combined </VirtualHost> |
Restart the Apache service to reload configuration:
1 | systemctl restart httpd |
Step 4: 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 Apache web server plugin:
1 | dnf install certbot python3-certbot-apache |
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 --apache -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 13 14 | 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 5: 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 6: 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 7: 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 |
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 |
Restart the Apache service:
1 | systemctl restart httpd |
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 Apache web server:
1 | chown -R apache:apache /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