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.

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

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 virtualsujit.com folder, you can make your own.

sudo mkdir /usr/share/nginx/virtualsujit.com
sudo mv wordpress/* /usr/share/nginx/virtualsujit.com

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;

exit;

Configuring WordPress

Go to your WordPress root folder :

cd /usr/share/nginx/yoursite.com/

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/yoursite.com/ -R

 

Create a config block file for WordPress :

sudo nano /etc/nginx/conf.d/yoursite.com.conf

 

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

server {
  listen 80;
  server_name www.yoursite.com yoursite.com;
  root /usr/share/nginx/yoursite.com/;
  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/yoursite.com/;
 }
}

 

Save and close the file.

Test Nginx configuration.

sudo nginx -t

If the test is successful, reload Nginx.

sudo systemctl reload nginx

 

Author: codeprojects
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments