Instructions for installing WordPress on CentOS 7

Tutorials 0 lượt xem
This post is part 4 of 7 in the LEMP for CentOS 7 series

In the previous posts, we have finished setting up LEMP. 

In this article, we’ll get started on installing WordPress on CentOS 7.

Create a database ​

Log in to MariaDB as the root user. 

mysql -u root -p

Create 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_html

Download the latest version of WordPress: 

wget http://wordpress.org/latest.tar.gz

Decompression: 

tar -zxvf latest.tar.gz

Move 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;
install wordpress on centos 7 1

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.conf

Give nginx permission to write files: 

chown nginx:nginx /home/nginx/khamphaso.com/public_html/nginx.conf

Open the file /etc/nginx/domains/khamphaso.com.conf and add the following: 

install wordpress on centos 7

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. ​

View articles in the series

Previous section: How to configure Nginx to optimize performance Next part: Zend OPcache installation and configuration guide

Bài viết liên quan