How to install WordPress in Ubuntu Nginx Server

WordPress is incredibly versatile, in that although it is primarily known as a blogging platform, it can be used to run a non-blog web site as well.


We already setup LEMP in ubuntu. If not then click the following link  

When you finished LEMP then come back here for WordPress installation.

First, update your software.

sudo apt-get update 
sudo apt-get upgrade

Now, download the latest WordPress tar from official sites of WordPress to your Ubuntu/ubuntu server which can be done by the following command.


Once download WordPress tar, extract the tar

tar xvf latest.tar.gz

A new WordPress folder will be created in your current working directory. Now create another folder in your Nginx root and move WordPress folder content into that folder. I have created folder, you can make your own.

sudo mkdir /usr/share/nginx/
sudo mv wordpress/* /usr/share/nginx/

Create a database and user for your WordPress site by opening MySQL shell.

MySQL -u root -p

Create database WordPress with your desired username and password by following ways:

create database wordpress;

create user yourusername@localhost;

set password for yourusername@localhost= password("your-password");

grant all privileges on wordpress.* to yourusername@localhost identified by 'your-password';

flush privileges;


Configuring WordPress

Go to your WordPress root folder :

cd /usr/share/nginx/

Copy the configuration file which is already there  and edit newly copied file :

sudo cp wp-config-sample.php wp-config.php
sudo nano wp-config.php

Find the following line and replace the red text with your created database, username and password.

/** The name of the database for WordPress */
define('DB_NAME', 'database_name_here');

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

/** MySQL database password */
define('DB_PASSWORD', 'password_here');


Save and close the file. Give the permission to this root folder :

sudo chown www-data:www-data /usr/share/nginx/ -R


Create a config block file for WordPress :

sudo nano /etc/nginx/conf.d/


Add the following text into that file and replace the red text with your own domain name.

server {
  listen 80;
  root /usr/share/nginx/;
  index index.php index.html index.htm;

  error_page 404 /404.html;
  error_page 500 502 503 504 /50x.html;

  location = /50x.html {
    root /usr/share/nginx/html;
  location / {
     try_files $uri $uri/ /index.php;

  error_page 404 /404.html;
  error_page 500 502 503 504 /50x.html;

 location ~ \.php$ {
   try_files $uri =404;
   fastcgi_pass unix:/run/php/php7.0-fpm.sock;
   fastcgi_index index.php;
   fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
   include fastcgi_params;
   root /usr/share/nginx/;


Save and close the file.

Test Nginx configuration.

sudo nginx -t

If the test is successful, reload Nginx.

sudo systemctl reload nginx


0 0 votes
Article Rating
Notify of
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x