How to Install WordPress on Nginx Powered VPS

WordPress is the most loved and most used blogging software in the world. It has now become far more than just a blogging software. It has unlimited possibilities. But to enjoy those possibilities to it’s fullest, WordPress will need friendly hosting background. I’m going show you how to build an ideal WordPress hosting background with Nginx, PHP and MySQL on an unmanaged Ubuntu 14.04 VPS.

I’m using Nginx instead of Apache. Apache is still a great http server software. I’ve used it for years. But Nginx is lightweight and faster than Apache. I know this from my experience. And it has everything that WordPress needs to function.

You server’s hardware also play a part in your Website’s speed. Although it’s called virtual server, it’s on a physical server somewhere in the world. That server’s speed and performance also matters when it comes to your website’s speed. So it’s essential to have a server with latest hardware. My personal recommendations for unmanaged VPS are listed on Best Unmanaged VPS (This article includes exclusive discounts). All their servers has latest hardware and their VPS packages are unbelievably cheap!

Setting up WordPress on NGINX is very simple. I’m not going to include initial server setup part on post since I have posted an easy to follow, copy-paste tutorial on Ubuntu-Nginx server setup. So before you read further down, you should follow that tutorial to prepare your unmanaged VPS for hosting websites. Following this post alone won’t get your sites online.

Assuming that you’ve configured your VPS with Nginx, PHP and MySQL as per my instructions, let’s add a new WordPress site to your server. You should also replace all instances of example.com with your domain name.

First step is to create a directory to hold your WordPress site,

sudo mkdir -p /var/www/example.com/htdocs/ /var/www/example.com/logs/

Change to that directory,

cd /var/www/example.com/htdocs/

Let’s download WordPress installation package to that directory and extract files within that directory,

sudo wget http://wordpress.org/latest.tar.gz
sudo tar --strip-components=1 -xvf latest.tar.gz
sudo rm latest.tar.gz

Grant files permissions to Nginx,

sudo chown -R www-data:www-data /var/www/example.com/

Nginx will need a virtual host file with rewrite rules to be able to route requests to this folder. If not, it’ll pass all requests to its default web directory. In that case you’ll see the Nginx welcome page when you open your domain in browser.

So let’s create a nginx virtual host file,

sudo nano /etc/nginx/sites-available/example.com

(Got -bash: nano: command not found?)

Now paste following lot into that file (Simply right clicking will do it.),

server {
        server_name example.com www.example.com;

	access_log   /var/log/nginx/example.com.access.log;
	error_log    /var/log/nginx/example.com.error.log;

        root /var/www/example.com/htdocs;
        index index.php;

        location / {
                try_files $uri $uri/ /index.php?$args; 
        }

        location ~ .php$ {
                include fastcgi_params;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
        }
}

Press Ctrl+X and then y to save and exit virtual host file. Next step is to create a symlink to that file in site-enabled directory.

sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/

Restarting Nginx will activate the new virtual host,

sudo service nginx reload

If that don’t throw you an error, your WordPress will be now online. But we’re not finished yet. WordPress needs a MySQL database to function. So let’s create one for it. Login to MySQL with root password. You set this up when you were installing MySQL on initial server setup.

(Forgot it? Then reset MySQL root Password)

mysql -u root -p

Create a new user. Replace db_user and db_pass with your desired username and password.

grant all privileges on *.* to db_user@localhost identified by "db_pass";

Create a new database. Again replace db_name with desired database name.

create database db_name;

Finally quit MySQL,

quit

That’s it. You’re good to go. Now open your domain name in browser and run the WordPress web installer before someone else does.

Tharindu

Hey!! I'm Tharindu. I'm from Sri Lanka. I'm a part time freelancer and this is my blog where I write about everything I think might be useful to readers. If you read a tutorial here and want to hire me, contact me here.

Leave a Reply

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

Back to top button