In the previous posts, we have finished setting up LEMP.
In this article, we’ll get started on installing WordPress on CentOS 7.
Contents
Create a database
Log in to MariaDB as the root user.
mysql -u root -pCreate a database named wordpress. Change the database name to suit your needs:
CREATE DATABASE wordpress;Create user:
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'wppassword';Give the user permission to access the database and then exit Maria DB
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost' IDENTIFIED BY 'wppassword';
FLUSH PRIVILEGES;
exit;
Install WordPress
Go to the folder containing the source code of the website you created in this article : (replace the domain with your own)
cd /home/nginx/khamphaso.com/public_htmlDownload the latest version of WordPress:
wget http://wordpress.org/latest.tar.gzDecompression:
tar -zxvf latest.tar.gzMove out to the root public_html folder and delete the empty wordpress folder:
mv wordpress/* /home/nginx/khamphaso.com/public_html && rm -rf wordpress
Attach nginx users and groups to files and directories:
chown -R nginx:nginx *Now go to http://your_domain.com and install WordPress via the web interface as usual.
Configure NGINX for WordPress
Nginx does not use .htaccess files like Apache to do things like rewrite paths, security, etc.
First you need to set up a permalink rule for Nginx to avoid 404 errors.
Open the file /etc/nginx/domains/your_domain.com.conf, for example /etc/nginx/domains/khamphaso.com.conf :
Then find the location segment and replace it as below:
try_files $uri $uri/ /index.php?$args;
Restart nginx: systemctl restart nginx
Configure nginx for important plugins (W3 Total Cache…)
Some plugins like W3 Total Cache support Nginx by writing its rules to the nginx.conf file in the public_html directory. If not, it will create it automatically.
Our job is to include this file in the nginx configuration file for the domain.
First we open the nginx configuration file for WordPress. If not, nano will create for us:
nano /home/nginx/khamphaso.com/public_html/nginx.confGive nginx permission to write files:
chown nginx:nginx /home/nginx/khamphaso.com/public_html/nginx.confOpen the file /etc/nginx/domains/khamphaso.com.conf and add the following:

Restart nginx: systemctl restart nginx.
Now you just need to install the W3 Total Cache plugin and you will see that it will write the content to the nginx.conf file but you need to restart nginx for it to work.
For plugins that do not support writing rules for Nginx, you can use this tool to get the configuration code.
At this point you have completed the installation of WordPress on CentOS 7.
If you have any questions, leave a comment below.

