Install WordPress on Nginx CentOS Server

Before to install Wordpress online on Nginx CentOS Server, we should verify that NGINX MySQL PHP (LEMP) has been installed and all of the LEMP services are started and running.

The most important thing is Nginx WordPress configuration for domain.tld. Assume has been configured as virtual host on our server, edit virtual.conf and insert configuration below:

#vi /etc/nginx/conf.d/virtual.conf
# Upstream to abstract backend connection(s) for php
upstream php {
server unix:/tmp/php-cgi.socket;

server {
listen 80;
## Your website name goes here (servername
server_name domain.tld;
## Your only path reference.
root /var/www/;
## This should be in your http block and if it is, it's not needed here.
index index.php;

location = /favicon.ico {
log_not_found off;
access_log off;

location = /robots.txt {
allow all;
log_not_found off;
access_log off;

location / {
# This is cool because no php is touched for static content.
# include the "?$args" part so non-default permalinks doesn't break when using query string
try_files $uri $uri/ /index.php?$args;

location ~ \.php$ {
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
include fastcgi.conf;
fastcgi_intercept_errors on;
fastcgi_pass php;

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
#Fix Yoast SEO Sitemaps
rewrite ^/sitemap_index\.xml$ /index.php?sitemap=1 last;
rewrite ^/([^/]+?)-sitemap([0-9]+)?\.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;

Save and Exit then Restart nginx and php-fpm service again so that all of the changes take effect:

#service nginx restart
#service php-fpm restart

Step one: Download WordPress directly from their website.

Make sure current directory is /var/www/

#cd /var/www/

Unzip it the the next line:

#tar -xzvf latest.tar.gz

After we unzip the wordpress files, they will be in a directory called wordpress in the current directory.
Copy all files and folder on that wordpress directory to /var/www/

#cp -R wordpress/* /var/www/

We will need to create an /upload directory on /var/www/wp-content/ folder so we can make contents and upload files into it.

#mkdir -p /var/www/wp-content/uploads

Grant Ownership Permissions of directory to user

#chown -R user:nginx /var/www/

Step Two: Create the WordPress Database and User.

#mysql -u root -p
Query OK, 1 row affected (0.00 sec)

Then we need to create the new user. You can replace the database, name, and password

mysql>CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'password';
Query OK, 0 rows affected (0.00 sec)

Finish up by granting all privileges to the new user.

Query OK, 0 rows affected (0.00 sec)

Then refresh MySQL:

Query OK, 0 rows affected (0.00 sec)

Exit out of the MySQL shell:


Step Three Setup the WordPress Configuration
The first step to is to copy the sample wordpress configuration file (wp-config-sample.php) into a new file wp-config.php which we will edit,  assume current working directory is /var/www/;

#cd /var/www/
#cp wp-config-sample.php wp-config.php

Then open the wordpress config:

#vi wp-config.php

Find the section that contains the field below and substitute in the correct name for your database, username, and password:

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wpdb');

/** MySQL database username */
define('DB_USER', 'wpuser');

/** MySQL database password */
define('DB_PASSWORD', 'password');
Save and Exit.


From here, WordPress has its own easy to follow installation form online. However, the form does require a specific php module to run. If it is not yet installed on your server, download php-gd:

#yum install php-gd

Restart nginx and php-fpm service again so that all of the changes take effect:

#service httpd restart

Step Five RESULTS Access the WordPress Installation
Access the page by adding /wp-admin/install.php to your site’s domain or IP address (eg. and fill out the short online form

Leave a Reply

Your email address will not be published. Required fields are marked *