How to Install WordPress on CentOS 8 (Step by Step) Tutorial

How to Install WordPress on CentOS 8. This article will explain installation guide of WordPress onCentOS 8 with an introduction of what WordPress is and its benefits.

What is WordPress?

WordPress is an open source and one of the most popular content management systems(CMS) written in PHP that uses a MySQL database. It is licensed under GPLv2 so free to install and it allows you to configure static or dynamic websites. It comes with massive ecosystem of WordPress plugins and themes to create a blog of your choice or create an e-commerce website and sell physical products using Word Press. If you are looking to set up flexible blogs and websites then WordPress CMS is a great choice for getting a website up and running quickly.

Pros of WordPress

  • A free and open source platform.
  • No HTML coding required.
  • Unlimited Pages, Posts, Products & More.
  • Full editing control of your website.
  • Extendable with WordPress plugins.
  • Website security.
  • Single Sign On (SSO).
  • Large community of users and developers.
  • Great codebase for SEO.
  • Website Portability & Vendor Lock in Avoidance.
  • Core Upgrades & Plugin Updates.
  • Stability & Reliability.
  • Automatic Backups.
  • Multisite.
  • Search Engines like Word Press sites.

In this step by step guide, we will demonstrate how to install WordPress with Nginx server on CentOS 8.

Install WordPress on CentOS 8

Step 1 - Install LEMP Server

First step of our tutorial how to Install WordPress on CentOS 8 is to download A LEMP server. It is a set of open source software (Linux, Nginx, MariaDB, PHP) used to host dynamic websites and applications on the internet. A LEMP stack would be preferable as Nginx performs approximately 2.5 faster than Apache server.

Install Nginx Web Server

By default, the Nginx package is included in the CentOS 8 default repo. You can install it using the following command:

				
					dnf install nginx -y
				
			

Once the Nginx server has been installed, start the Nginx service and enable it to start after the system reboot.

				
					systemctl start nginx
systemctl enable nginx
				
			

You can also check the Nginx version using the following command:

				
					nginx -v
				
			

Sample output:

				
					nginx version: nginx/1.14.1
				
			

Install MariaDB Database Server

WordPress uses MySQL or MariaDB as a database backend. You can install the MariaDB database by just running the following command:

				
					dnf install mariadb-server -y
				
			

After installing the MariaDB database, start the MariaDB service and enable it to start at system reboot:

				
					systemctl start mariadb
systemctl enable mariadb
				
			

Next, you will need to secure the MariaDB installation and set a MariaDB root password. You can do it by running the following script:

				
					mysql_secure_installation
				
			

You will be asked to set a root password, remove anonymous users, disallow root login remotely and remove the test database as shown below:

				
					Enter current password for root (enter for none): 
Set root password? [Y/n] Y
New password: 
Re-enter new password: 
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y
				
			

Install PHP 8

PHP version 8 has significant performance improvements and new features so it is recommended to use PHP 8 for WordPress. By default, PHP 8 is not included in the CentOS 8 default repo. So you will need to install the EPEL and Remi PHP repository to your system.

First, install EPEL and Remi repository package with the following command:

				
					dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
				
			

Next, disable the default PHP repository and enable the PHP Remi repository using the following command:

				
					dnf module reset php
dnf module install php:remi-8.0 -y
				
			

Next, install PHP 8 with other necessary PHP extensions using the following command:

				
					dnf install php php-mysqlnd php-fpm php-opcache php-curl php-json php-gd php-xml php-mbstring php-zip -y
				
			

Once the installation is completed, verify the PHP version using the following command:

				
					php -v
				
			

Sample output:

				
					PHP 8.0.9 (cli) (built: Jul 29 2021 12:53:58) ( NTS gcc x86_64 )
Copyright (c) The PHP Group
Zend Engine v4.0.9, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.9, Copyright (c), by Zend Technologies
				
			

Nginx uses a PHP-FPM to process the PHP files. By default, PHP-FPM is configured to run as an Apache user. So you will need to configure it for Nginx.

				
					nano /etc/php-fpm.d/www.conf
				
			

Change the user and group from apache to nginx as shown below:

				
					user = nginx
group = nginx
				
			

Save and close the file then start the PHP-FPM service and enable it to start at system reboot:

				
					systemctl start php-fpm
systemctl enable php-fpm
				
			

Step 2 - Create a Database for WordPress

Next, you will need to create a database and user for WordPress. First, log in to MariaDB shell with the following command:

				
					mysql -u root -p
				
			

Once you are log in, create a database and user with the following command:

				
					CREATE DATABASE wordpressdb;
CREATE USER `wordpressuser`@`localhost` IDENTIFIED BY 'securepassword';
				
			

Next, grant all the privileges to the WordPress database with the following command:

				
					GRANT ALL ON wordpressdb.* TO `wordpressuser`@`localhost`;
				
			

Next, flush the privileges and exit from the MariaDB shell with the following command:

				
					FLUSH PRIVILEGES;
EXIT;
				
			

Step 3 - Download WordPress

It is always recommended to download the latest version of WordPress from its official website. You can download it inside the Nginx default root directory using the following command:

				
					cd /var/www/html
wget https://wordpress.org/latest.tar.gz
				
			

Once the download is completed, extract the downloaded file with the following command:

				
					tar -xvzf latest.tar.gz
				
			

Next, rename the extracted directory with yourdomain name.

				
					mv wordpress yourdomain.com
				
			

Next, change the ownership of yourdomain.com directory to nginx:

				
					chown -R nginx:nginx /var/www/html/yourdomain.com
				
			

Step 4 - Create Nginx Virtual Host for WordPress

Next, you will need to create a separate Nginx virtual host configuration file to serve the WordPress website.

				
					nano /etc/nginx/conf.d/yourdomain.conf
				
			

Add the following lines:

				
					server {
   listen 80;
   server_name yourdomain.com www.yourdomain.com;

   root /var/www/html/yourdomain.com;
   index index.php index.html index.htm;

   location / {
      try_files $uri $uri/ =404;
   }
   error_page 404 /404.html;
   error_page 500 502 503 504 /50x.html;
   location = /50x.html {
      root /usr/share/nginx/html;
   }

   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;
   }
}
				
			

Save and close the file then run the following command to verify the Nginx for any syntax error.

				
					nginx -t
				
			

Sample output:

				
					nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
				
			

Finally, reload the Nginx service to apply the configuration changes:

				
					systemctl restart nginx
				
			

Step 5 - Configure SELinux and Firewall

By default, SELinux is enabled on CentOS 8 server. It is always recommended to disable the SELinux. To disable the SELinux, edit the /etc/selinux/config file:

				
					nano /etc/selinux/config
				
			

Change the following line:

				
					SELINUX=disabled
				
			

Save and close the file then restart your system to apply the changes.

Next, you will also need to allow HTTP and HTTPS service through the firewall. You can allow them by running the following command:

				
					firewall-cmd --permanent --zone=public --add-service=http 
firewall-cmd --permanent --zone=public --add-service=https
				
			

Next, reload the firewall daemon to apply the changes:

				
					firewall-cmd --reload
				
			

Step 6 - Enable HTTPS for WordPress

Let’s Encrypt is a non profit certificate authority that provides a free SSL certificate to create a more secure and privacy respecting Web.
To download the Let’s Encrypt server SSL and implement it on your website, you will need to install the Certbot client package on your server.

Run the following command to install the Certbot client package for Nginx:

				
					dnf install certbot python3-certbot-nginx -y
				
			

Once the Certbot package is installed, run the following command to enable the SSL on your WordPress website.

				
					certbot --nginx --agree-tos --redirect --hsts --uir --staple-ocsp --email user@yourdomain.com -d yourdomain.com,www.yourdomain.com
				
			

This command will download the Let’s Encrypt SSL and configure your Nginx virtual host configuration file to use those SSL certificates. 

Next, you will need to set up a cron job to renew the Let’s Encrypt certificate automatically. To do so edit the cron job with the following command:

				
					crontab -e
				
			

Add the following line:

				
					@daily certbot renew --quiet && systemctl reload apache2
				
			

Save and close the file when you are finished.

Step 7 - Access WordPress Website

You can now access the WordPress installation wizard by visiting the URL https://yourdomain.com. You will be redirected to the language selection page:

Select your language and click on the Continue button. You should see the following page:

Click on the Let’s go! button. You will be redirected to the database configuration page:

Provide your database configuration details and click on the Submit button. You should see the following page:

Click on the Run the installation button. You should see the WordPress site configuration page:

Provide your website information and click on the Install WordPress button. Once the installation has been finished, you should see the following page:

Click on the Log In button. You should see the WordPress login page:

Provide your admin credentials and click on the Log In button. You should see the WordPress dashboard page:

Install WordPress on CentOS 8 Conclusion

In the above guide, we explained how to install WordPress with Nginx and Let’s Encrypt SSL on CentOS 8. You can now start creating your own blog or website using WordPress and host it on the internet.

Avatar for Hitesh Jethva
Hitesh Jethva

I am a fan of open source technology and have more than 10 years of experience working with Linux and Open Source technologies. I am one of the Linux technical writers for Cloud Infrastructure Services.

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x