Rocky Linux is a new Linux distribution that is based on the source code of Red Hat Enterprise Linux (RHEL) and CentOS. It aims to provide a stable, secure, and performant platform for running Linux-based applications and services. In this article, we will explain how to install WordPress with Nginx and Let’s Encrypt SSL on Rocky Linux.
Before you begin, make sure that you have a Rocky Linux server that is connected to the internet, and that you have a non-root user with sudo privileges.
To install WordPress with Nginx and Let’s Encrypt SSL on Rocky Linux, you first need to update the package list and install the required packages by running the following commands:
sudo yum update
sudo yum install epel-release
sudo yum install nginx mariadb-server mariadb php php-mysqlnd php-fpm
These commands will update the package list, install the epel-release
package, which provides additional packages for Rocky Linux, and install the Nginx web server, the MariaDB database server, the PHP programming language, and the PHP-FPM module.
Once the required packages are installed, you need to start and enable the Nginx and MariaDB services by running the following commands:
sudo systemctl start nginx
sudo systemctl enable nginx
sudo systemctl start mariadb
sudo systemctl enable mariadb
These commands will start the Nginx and MariaDB services and configure them to start automatically on boot.
Next, you need to secure the MariaDB server by running the mysql_secure_installation
script:
sudo mysql_secure_installation
This script will guide you through the process of securing the MariaDB server. It will ask you to set a password for the MariaDB root user, remove the anonymous user accounts, disable remote root logins, and remove the test database. It is recommended that you follow the default options and answer “yes” to all questions.
Once the MariaDB server is secured, you need to create a database and a user for WordPress by running the following commands:
sudo mysql -u root -p
This will open the MariaDB shell. Next, run the following commands to create a database and a user for WordPress:
CREATE DATABASE wordpress;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
These commands will create a database called wordpress
, a user called wpuser
with the password password
, and grant the user full privileges on the WordPress database.
Once the database and the user are created, you can download the latest version of WordPress by running the following commands:
cd /var/www/html
wget <https://wordpress.org/latest.tar.gz>
Once the WordPress files are downloaded, you need to extract the archive and move the files to the correct directory by running the following commands:
sudo tar -xzf latest.tar.gz
sudo mv wordpress /var/www/html/
These commands will extract the WordPress files from the archive and move them to the /var/www/html/
directory, which is the default directory for web content on Rocky Linux.
Next, you need to create a configuration file for WordPress by copying the wp-config-sample.php
file and modifying it to match your WordPress installation:
sudo cp /var/www/html/wordpress/wp-config-sample.php /var/www/html/wordpress/wp-config.php
sudo vi /var/www/html/wordpress/wp-config.php
This will copy the wp-config-sample.php
file to wp-config.php
and open the file in the vi
text editor. In the file, you need to modify the following lines:
define('DB_NAME', 'wordpress');
define('DB_USER', 'wpuser');
define('DB_PASSWORD', 'password');
These lines define the database name, the database user, and the database password for your WordPress installation. You need to replace the wordpress
, wpuser
, and password
values with the actual values that you used when creating the database and the user.
Once you have modified the wp-config.php
file, you need to save the file and exit the vi
editor.
Now that the WordPress files are in place and the configuration is set up, you need to create an Nginx configuration file for your WordPress site by running the following commands:
sudo vi /etc/nginx/conf.d/your_domain.com.conf
This will create a new configuration file for your WordPress site and open it in the vi
editor. In the file, you need to add the following lines:
server {
listen 80;
server_name your_domain.com;
root /var/www/html/wordpress;
index index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \\.php$ {
include fastcgi_params;
fastcgi_pass unix:/run/php-fpm/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
These lines define the settings for your WordPress site, including the listening port (80
), the server name (your_domain.com
), the root directory (/var/www/html/wordpress
), and the location of the PHP files (/index.php
). The location
blocks define the rules for handling requests to your WordPress site, including how to handle requests to PHP files.
Once you have added the configuration lines to the Nginx configuration file, you need to save the file and reload the Nginx service to apply the changes:
sudo systemctl reload nginx
This will reload the Nginx service and apply the new configuration.
Now that Nginx is configured, you can proceed with installing the Let’s Encrypt SSL certificate for your WordPress site. To do this, you need to install the certbot
package by running the following command:
sudo yum install certbot
This command will install the certbot
package, which includes the tools for generating and managing SSL certificates with Let’s Encrypt.
Once the certbot
package is installed, you can generate an SSL certificate for your WordPress site by running the following command:
sudo certbot certonly --webroot -w /var/www/html/wordpress -d your_domain.com
This command will run the certbot
tool in certonly
mode, which generates an SSL certificate but does not automatically configure Nginx to use it. The --webroot
option specifies that certbot
should use the webroot authentication method, and the -w
and -d
options specify the webroot directory and the domain name for your WordPress site, respectively.
The certbot
tool will ask you to provide an email address for receiving renewal notices and to agree to the terms of service. After you have provided this information, certbot
will generate the SSL certificate and store it in the /etc/letsencrypt/live/your_domain.com
directory.
Now that you have generated the SSL certificate, you need to modify the Nginx configuration file to use it. To do this, open the Nginx configuration file in the vi
editor:
sudo vi /etc/nginx/conf.d/your_domain.com.conf
Next, add the following lines to the configuration file:
server {
listen 80;
server_name your_domain.com;
root /var/www/html/wordpress;
index index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \\.php$ {
include fastcgi_params;
fastcgi_pass unix:/run/php-fpm/www.sock
Next, you need to add the SSL certificate and key files to the Nginx configuration file. To do this, add the following lines to the server
block in the configuration file:
ssl on;
ssl_certificate /etc/letsencrypt/live/your_domain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/your_domain.com/privkey.pem;
These lines enable SSL for the server, and specify the paths to the SSL certificate and key files that were generated by certbot
.
Once you have added the SSL certificate and key files to the Nginx configuration file, you need to save the file and reload the Nginx service to apply the changes:
sudo systemctl reload nginx
This will reload the Nginx service and apply the new configuration.
Now that your WordPress site is configured with Nginx and Let’s Encrypt SSL, you can access it through a web browser by visiting the URL of your WordPress site (https://your_domain.com
in this example). If the installation and configuration were successful, you should see the WordPress installation wizard, where you can set up the basic details for your WordPress site, such as the site title, the username and password for the admin account, and the email address for the admin account.
In conclusion, installing WordPress with Nginx and Let’s Encrypt SSL on Rocky Linux is a straightforward process that involves installing the required packages, configuring the database and the web server, and generating an SSL certificate with certbot
. By following the steps outlined in this article, you can quickly and easily set up a secure WordPress site on Rocky Linux.