How To Install WordPress on Rocky Linux (Nginx LEMP server)

by

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 install a WordPress website with a domain name on a Rocky Linux server running a LEMP stack with Nginx.

Prerequisites:

  • Rocky Linux LEMP server (follow this tutorial if you don’t have one)
  • Domain name

Notes:

  1. Replace tonys.store with the name of your domain name in this tutorial
  2. A complete video tutorial is available at the end of this tutorial

1. Point Domain Name at Server

Login to wherever you bought your domain name, find the DNS settings, and create two A records:

  • Point tonys.store to the IP address of your server
  • Point www.tonys.store to the IP address of your server

If you need more help setting up your A records, check out this video.

2. Download WordPress

Download and extract the official WordPress package to the web directory of your Rocky Linux server, and apply the appropriate permissions.

cd /var/www/
curl https://wordpress.org/latest.tar.gz --output wordpress.tar.gz
tar xf wordpress.tar.gz
rm wordpress.tar.gz
chown -R nginx:nginx /var/www/wordpress
find /var/www/wordpress -type d -exec chmod 755 {} \;
find /var/www/wordpress -type f -exec chmod 644 {} \;

3. Configure the Nginx Web Server

Create a file called wordpress.conf in the /etc/nginx/conf.d/ directory with the following content. Replace the server_name with your own.

server {
   listen 80;
   server_name tonys.store www.tonys.store;

   root /var/www/wordpress/;
   index index.php;

   location / {
      try_files $uri $uri/ =404;
   }

   location ~ \.php$ {
      try_files $uri =404;
      fastcgi_pass unix:/var/run/php-fpm/www.sock;
      fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      include fastcgi_params;
   }
}

Apply this change by restarting the web server.

nginx -t
systemctl restart nginx
systemctl status nginx

3. Setup the WordPress Database

Access the MySQL command prompt.

mysql -u root -p

Create an empty database for WordPress.

create database db_name;
create user 'example_db'@'localhost' identified by 'example_pw';
grant all privileges on example_db.* TO 'example_uer'@'localhost';
flush privileges;
exit

4. Install Additional PHP Modules

When you navigate to your website in a web browser, you will see an error that says:

Your PHP installation appears to be missing the MySQL extension which is required by WordPress.

 

your php installation appears to be missing the mysql extension which is required by wordpressPin

To fix this error, use the dnf package manager to install this required MySQL extension in addition to other PHP modules recommended by WordPress.

dnf install php-mysqlnd php-gd php-json php-mbstring php-pecl-zip php-xml curl

5. Allow Nginx to Work with SELinux

You must explicitly change the SELinux security context of the WordPress directory to avoid the wp-config.php write error message during the installation of WordPress.

Unable to write to wp-config.php file.

Unable to write to wp-config.php filePin

To change the SELinux security context, execute the following chcon command.

chcon -R -t httpd_sys_rw_content_t /var/www/wordpress/

You must also tell SELinux to allow web server scripts and modules to connect to the network to avoid cURL error 7.

Error: cURL error 7: (http_request_failed)

curl error 7 http_request_failedPin

Once you have WordPress installed (after the next step), you can check your site’s status from the WordPress administrator dashboard under Tools > Site Health.

To change this SELinux setting, execute the following sesetbool command.

setsebool httpd_can_network_connect true

6. Finish WordPress Install

You can now access your website via your domain name in a web browser. You will be prompted to finish the WordPress installation, part of which is entering the database name, user, and password that you created earlier.

WordPress database setupPin

Upon completion of the installation, you can access your WordPress administrator dashboard at http://tonys.store/wp-admin/

YouTube video

Next Steps

Now that you have a fresh install of WordPress, check out 15 important things to do after installing WordPress which includes installing an SSL certificate for a secure HTTPS website.


Meet Tony

With a strong software engineering background, 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 Comment