How To Install Wordpress with nginx on CentOS 6

Riddhi Jindal
Riddhi Jindal

Created: 05/20/2020 2:13 PM - Updated: 05/20/2020 2:13 PM

How To Install Wordpress with nginx on CentOS 6


Root privileges on the VPS

LEMP installed on the VPS

Step One—Download WordPress

tar -xzvf latest.tar.gz 

Step Two—Create the WordPress Database and User

mysql -u root –p
Query OK, 1 row affected (0.00 sec)
CREATE USER wordpressuser@localhost;
Query OK, 0 rows affected (0.00 sec)
SET PASSWORD FOR wordpressuser@localhost= PASSWORD("password");
Query OK, 0 rows affected (0.00 sec)
GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser@localhost IDENTIFIED BY 'password';
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)

Step Three—Setup the WordPress Configuration

cp ~/wordpress/wp-config-sample.php ~/wordpress/wp-config.php
sudo vi ~/wordpress/wp-config.php

Find the section that have below fields and change 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', 'wordpress');
/** MySQL database username */
define('DB_USER', 'wordpressuser');
/** MySQL database password */
define('DB_PASSWORD', 'password');

Save and Exit.

Step Four—Copy the Files

sudo mkdir -p /var/www/wordpress
sudo cp -r ~/wordpress/* /var/www/wordpress
cd /var/www/
sudo chown nginx:nginx * -R
sudo usermod -a -G nginx username

Step Five—Set Up Nginx Server Blocks

sudo vi /etc/nginx/conf.d/default.conf

The configuration should include the changes below (the details of the changes are under the config information):

# The default server
server {
    listen       80;
    server_name  _;
    #charset koi8-r;
    #access_log  logs/host.access.log  main;
    location / {
        root   /var/www/wordpress;
        index index.php  index.html index.htm;
    error_page  404              /404.html;
    location = /404.html {
        root   /usr/share/nginx/html;
    # redirect server error pages to the static page /50x.html
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    # proxy the PHP scripts to Apache listening on
    #location ~ \.php$ {
    #    proxy_pass;
    # pass the PHP scripts to FastCGI server listening on
    location ~ \.php$ {
        root           /var/www/wordpress;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #location ~ /\.ht {
    #    deny  all;
  • Add index.php in the index line.
  • Change  root to /var/www/wordpress;
  • Uncomment the section "location ~ \.php$ {",
  • Change root to access the actual document root, /var/www/wordpress;
  • Change the fastcgi_param line

Save and exit.

sudo service nginx restart

Step Six—Access the WordPress Installation

When all the above steps are completed successfully access the page by visiting your site's domain or your Virtual Private Server's IP address and fill out the short online form.

Was this article helpful?

0 Out of 0 Marked As Helpfull

Have more questions? Please Contact Us