In this guide, we will go through Setting up Mysql 8 and the latest wordpress in Centos 8 with Nginx serving traffic and terminating ssl.
WordPress is a free and open-source content management system written in PHP and paired with a MySQL or MariaDB database. Welcome to the world’s most popular website builder. 42% of the web is built on WordPress.
Related Content:
Prerequisites
To follow along this guide, ensure that you have the following:
- Centos 8 Server
- Root access or user with sudo access
- Domain name with A DNS records mapped to the server
- Internet access from the server
Updating the system
Ensure that your system is up to date before proceeding. Use the following command to update the packages:
|
|
Output:
|
|
Install the MySQL 8 Database Server
Note: To see a detailed guide on installing mysql server, check this guide here.
Now that the system is updated, lets install mysql server. Mysql is available in the Centos 8 repositories as mysql-server
package. Install it with this command:
|
|
Once installation is done, start the service using this command:
|
|
Enable the service to start on boot:
|
|
Finally, use the mysql provided secure installation command to set up the initials and the password for mysql user.
|
|
Note down the root password.
Create Mysql wordpress user
It is always a good practice to create a dedicated user to use when connecting to the database from mysql. Login as the root user and use these commands to create a user:
Create a database to be used by our site:
|
|
Create a user:
|
|
Grant the created user privileges to the db:
|
|
Now save the database, user and the password for use when we have wordporess installed.
Install the Nginx Web Server
We will use nginx to serve traffic comming in from the designated domain to our wordpress site. We will need to have a virtual host and a domain already mapped to the server that we will use to serve wordpress.
To install Nginx:
|
|
Once the installation is completed, start Nginx and enable it to start automatically after a reboot:
|
|
You can check if the web server is running with this command:
|
|
Output
|
|
Install PHP with dependencies
WordPress is Coded in PHP. We will need php runtime to serve wordpress in our server.
WordPress works in PHP 7.4. The latest version of php is not available in the default Centos Repositories. Let’s enable it with this command:
|
|
Now enable php 7.4 with this command:
|
|
Now let’s install phpuse this command to install:
|
|
Configure PHP and PHP FPM Settings
Global php settings are stored in the /etc/php.ini
file. Lets update these settings.
Open php.ini with your favourite text editor, I will use vim
|
|
Search for the following and update the values like shown below:
|
|
php-fpm
is responsible for serving our php content, its config file is located here: /etc/php-fpm.d/www.conf
.
Now open the /etc/php-fpm.d/www.conf
configuration file:
|
|
Look for the user and group directives. Make the following changes from apache to nginx:
|
|
Save and close the file, then restart the PHP-FPM service to apply the configuration changes:
|
|
7. Download and Install WordPress
Now that we have the servers set up, let’s download and install wordpress on the server. The latest release of WordPress can be downloaded from their official website.
Let’s create a directory where our wordpress content willl be served:
|
|
Ensure that the nginx
user owns the content:
|
|
Download the latest wordpress content:
|
|
Sample Output:
|
|
Extract and move the content to our server directory:
|
|
Configuring wordpress
Now that the wordpress content has been copied to the site directory, lets update the db configuration using the sample file provided.
Switch to the site directory:
|
|
Copy your wp-config-sample
file to wp-config.php
.
|
|
Open the config file in a text editor:
|
|
Update these vars: DB_NAME
, DB_USER
, DB_PASSWORD
, DB_HOST
:
|
|
Save the text file once that is done.
Make the Nginx user as the owner of the WordPress directory, so that it has access and is able to serve the files.
|
|
Configure Nginx to serve the site
Now that the config is in place, lets configure an nginx virtual host to serve the content we just added to /var/www/dev-citizix
.
Let’s create virtual site in the directory that nginx serves content here /etc/nginx/conf.d
:
|
|
Add the following content:
|
|
Ensure that the added config is good by using this command to test:
|
|
Once you confirm that everything is OK, restart Nginx for the changes to take effect:
|
|
10. Complete the WordPress installation
Once all steps above are done, the installation from the command line is completed. You can open your favorite web browser and point it to your set up domain -http://blog.citizix.com. You should get the wordpress setup screen.
From there you can follow the prompts to set up your wordpress.
Conclusion
We managed to set up Centos 8 with Mysql 8, Php 7.4 and Nginx to serve wordpress in this guide.