How to set up WordPress on Ubuntu 14.04 with Nginx at DigitalOcean

How to set up WordPress on Ubuntu 14.04 with Nginx at DigitalOcean

This is a step by step how-to.

This how-to is based on the folowing prerequisites:

  1. You’ve already signed-up at DigitalOcean (if not, grab a link, you’ll get $10 of credit with it).
  2. You’ve already purchased a domain name and it is directed to, ns2…, ns3… (if not, don’t worry, we’ll get to that).
  3. You can access remote server using ssh (windows users will need PuTTY software, for linux users including Mac OSX it’s a built in feature).

Ok, let’s begin.

Step 1. Create a DigitalOcean Droplet

Go on, login to and follow this video instruction:

Heads Up: note, that I’m choosing ‘LEMP on 14.04’ instead of ‘WordPress on 14.04’. That’s pretty important. We gonna use nginx as a HTTP server that is part of ‘LEMP on 14.04′ instead of ol’ rusty Apache that is packed with ‘WordPress on 14.04’.

If you don’t have already generated ssh key, get one or just don’t use this option. It’ll allow you to login via ssh without a password, but who cares? You can always use good old password!

As a result you’ll create a VPS and get an access to it via SSH. Awesome!

Note, at the end you’ll see your MySQL root password. In my video it is blurred. Mark it somewhere, you’ll need it.

Step 2. Update apt-get indexes to be able to add packages

Oh, that’s easy enough:

apt-get update

Step 3. Secure MySQL server and install phpMyAdmin

Ok, by this time we have already installed MySQL server, but it has anonymous access, dummy databases, etc, etc. Let’s clean it up:


You can use default answers here or adjust them to your liking.

Me personally, I like managing MySQL databases using UI like phpMyAdmin, let’s install it.

apt-get install phpmyadmin php5-intl mcrypt
php5enmod mcrypt
service php5-fpm restart
service nginx restart

Step 4. Setup DNS.

Ok now let’s setup DNS. To get things working you need to:

  1. Point your domain registrar to your DigitalOcean name servers,, It is done somewhere inside your domain registrar admin area.
    Note: I mentioned this as a prerequisite because it can take up to 24+ hours to propagate info all over the world. So you’ll have to wait or do temporary /etc/hosts trick (on your local machine!)
  2. Point DigitalOcean name servers to your droplet, here’s the video instruction:

To check if everything ok, just open your domain in your browser. You should see the same nginx welcoming page that is shown if you type in your server’s ip (can be seen in DigitalOcean admin area on droplet page).

Step 5. Create site folder and add it to Nginx config

Let’s assume our domain is ‘’.

We gonna serve our sites from /var/www dir. Let’s create it:

mkdir /var/www

Now let’s create some global nginx configs:

cd /etc/nginx
mkdir global
cd global
nano restrictions.conf

My favourite nano editor will open. Paste the following config in there:

# Global restrictions configuration file.
# Designed to be included in any server {} block.
location = /favicon.ico {
    log_not_found off;
    access_log off;
location = /robots.txt {
    allow all;
    log_not_found off;
    access_log off;
# Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
# Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban)
location ~ /. {
    deny all;
# Deny access to any files with a .php extension in the uploads directory
# Works in sub-directory installs and also in multisite network
# Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban)
location ~* /(?:uploads|files)/.*.php$ {
    deny all;

Now hit ctrl + o (save), ctrl + x (exit).

Let’s create wordpress configuration:

nano wordpress.conf

Paste the following config in there:

# WordPress single blog rules.
# Designed to be included in any server {} block.
# This order might seem weird - this is attempted to match last if rules below fail.
location / {
    try_files $uri $uri/ /index.php?$args;
# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
# Directives to send expires headers and turn off 404 error logging.
location ~* ^.+.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
    access_log off; log_not_found off; expires max;
# Pass all .php files onto a php-fpm/php-fcgi server.
location ~ [^/].php(/|$) {
    fastcgi_split_path_info ^(.+?.php)(/.*)$;
    if (!-f $document_root$fastcgi_script_name) {
        return 404;
    # This is a robust solution for path info security issue and works with "cgi.fix_pathinfo = 1" in /etc/php.ini (default)
    include fastcgi_params;
    fastcgi_index index.php;
    # fastcgi_intercept_errors on;
    fastcgi_pass unix:/var/run/php5-fpm.sock;

ctrl + o, ctrl + x.

Now let’s create a config for our ‘’:

cd ../sites-available

Here is it:

server {
    root /var/www/;
    index index.php;
    include global/restrictions.conf;
    # Additional rules go here.
    include global/wordpress.conf;

ctrl + o, ctrl + x.

Now let’s enable this config in a standard nginx manner:

cd ../sites-enabled/
ln -s ../sites-available/

Well, we gotta restart nginx to get this config to action, but we haven’t created ‘/var/www/’ yet. Let’s fix it.

Step 6. Create website dir and put WordPress in it.

cd /var/www
mkdir -m 777
wget -O
mv ./wordpress/* .
rmdir ./wordpress

Yeehaa, let’s restart nginx and get things started!

service nginx restart

Ok, now you should be able to open your ‘’ in browser and see famous WordPress installation wizzard.

But before you proceed…

Step 7. Run phpMyAdmin and create a db for WordPress

Remember, long time ago, when you were much younger, on step 3, we’ve installed phpMyAdmin?

Let’s add it to our site:

cd /var/www/
ln -s /usr/share/phpmyadmin

Awesome! Now open

Login using username: ‘root’ and a password you got in the end of step 1.

And if you don’t know what to do follow this little video instruction:

In this video I’m creating database for the site ‘’. To keep things simple I set the same db name.

I don’t like the idea of storing mysql root credentials inside wordpress, so I’m creating a db user called the same ‘’ and give him full privileges for that db only.

Step 8. Install WordPress

Well by this time you’ve got everything to install WordPress. And I’ll leave it up to you.

I’m pretty sure that if you decided to setup VPS with nginx via ssh you know what to do with 5-minute WordPress installation wizard.

And I’ll go celebrate my first how-to in my own blog :)

{{"Show older comments..."|nls}}{{comments.length}} {{"of"|nls}} {{total}} {{"shown" | nls}}


{{(dialog.replies.length > 1?'Replies':'Reply')|nls}}: