How to deploy a WordPress blog into DigitalOcean hosting


After many years suffering a lot of server unavailability and very slow page loading of our 1and1 server, we decided to migrate to another low cost provider. not looking for best specifications but looking for best stability at similar price.

We decide to use DigitalOcean as provider because it is very easy to use and also very cheap. It has plans staring from 5 € per month and guarantee some minimum basic resources, enough for our purposes, also you can always increase or decrease your server specifications at any moment very easily, because the are cloud servers.

Moreover you will only pay for the hours you actually used the server, so you can shutdown your server if you don’t need it and you will not pay for it. Also you can increase your server specifications during a while, then return to your original plan and will only pay the superior plan price for the hours you used it.

Creating your first “droplet”

You have to sign up in DigitalOcean, also you can get profit of their referral program to get 10$ in order to do your test for free. The DigitalOcean referral program allow current clients sharing a special URL that will allow new clients to get 10$ for free and also, when this new client spent 25$, DigitalOcean gives to the URL’s owner another 25$. So both parts win.

If you want to follow this guide without spent money, you can use our referral URL:

Once you are signed up, it is time to create your droplet, where your web page will be hosted, following this steps:

Step 1: Name and plan selection


Step 2: Region y other settings


Step 3: Distribution


Step 4: Preinstalled software


Last step: SSH key


DNS server

Now you need to link our server to our domain, you will not need to make any domain transfer, just go to DNS tab, write your domain name and select the droplet you want to use for this domain. After that, you can see what are your assigned DNS servers and set it on your domain control panel.

DigitalOcean DNS configuration example


Setting up your Droplet

First of all, is important to improve your server security, otherwise you will be hacked in a few minutes, so start a new SSH session:

$ ssh root@SERVER_IP

As you added a SSH key, yuo will not be answered for password, but is very important setting a new as hard as possible root password:

# passwd

Now is time to create your user:

# adduser USER
# gpasswd -a USER sudo
# usermod -a -G www-data USER

Exit an log in again using your new user:

# exit

Copy your SHH key to your new user’s home in order to access without password and to improve security.

$ mkdir .ssh
$ chmod 700 .ssh
$ sudo cp /root/.ssh/authorized_keys .ssh/
$ sudo chown USER:USER .ssh/authorized_keys
$ chmod 600 .ssh/authorized_keys

Now you can do some tweak to the SSH server, to start, open configuration file:

# nano /etc/ssh/sshd_config

Change the default port:

Port 2234

Disable SSH root login and password login, allowing only SSH key login.

PermitRootLogin no
ChallengeResponseAuthentication no
PasswordAuthentication no
UsePAM no

Save and exit perrsing CTRL-X, then Y, and finally ENTER.

Restart SSH server:

# service ssh restart

Log out and log in again using the new port:

# exit

Enable the firewall and open necessary ports. First SSH port:

$ sudo ufw allow 2234/tcp

And then HTTP and SSL/TLS ports:

$ sudo ufw allow 80/tcp
$ sudo ufw allow 443/tcp

If you want to have SMTP server, you can open port 25, for example (I do not recommend):

$ sudo ufw allow 25/tcp

Now you can start the firewall:

$ sudo ufw enable

The next step is configuring the time zone and enabling NTP:

$ sudo dpkg-reconfigure tzdata
$ sudo apt-get update
$ sudo apt-get install ntp

To improve a little bit the server performance wen memory ram gets full, you can create a SWAP file:

$ sudo fallocate -l 512M /swapfile
$ sudo chmod 600 /swapfile
$ sudo mkswap /swapfile
$ sudo swapon /swapfile
$ sudo sh -c 'echo "/swapfile none swap sw 0 0" >> /etc/fstab'

Setting up your Web server

At this point, you have an acceptable configured server, so you can install and configure your web server.

Start creating needed directory structure:

$ sudo mkdir -p /var/www/EXAMPLE.COM/html
$ sudo chown -R www-data:www-data /var/www/EXAMPLE.COM/html
$ sudo chmod -R 775 /var/www

Add your domain to Nginx and configure it:

$ sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/EXAMPLE.COM
$ sudo nano /etc/nginx/sites-available/EXAMPLE.COM

Modify your configuration file to be similar to this:

# Cache
#fastcgi_cache_path /var/cache/nginx/EXAMPLE.COM levels=1:2 keys_zone=EJEMPLO.COM:10m max_size=128m inactive=1h;

#server {
# server_name "~^www\.(.*)$" ;
# return 301 $scheme://$1$request_uri ;

server {
 listen 80;
 listen [::]:80;

 root /var/www/EXAMPLE.COM/html;
 index index.php index.html index.htm;

 server_name EXAMPLE.COM www.EXAMPLE.COM;

 location / {
 try_files $uri $uri/ /index.php?q=$uri&$args;

 error_page 404 /404.html;
 error_page 500 502 503 504 /50x.html;
 location = /50x.html {
 root /usr/share/nginx/html;

 location ~ \.php$ {
 try_files $uri =404;
 fastcgi_split_path_info ^(.+\.php)(/.+)$;
 fastcgi_pass unix:/var/run/php5-fpm.sock;
 fastcgi_index index.php;
 #fastcgi_cache EXAMPLE.COM;
 #fastcgi_cache_key $scheme$host$request_uri$request_method;
 #fastcgi_cache_valid 200 301 302 5s;
 #fastcgi_cache_use_stale updating error timeout invalid_header http_500;
 include fastcgi_params;

gzip on;
gzip_comp_level 2;
gzip_min_length 1000;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain application/x-javascript text/xml text/css application/xml;

location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
 expires 1w;
 add_header Pragma public;
 add_header Cache-Control "public";
 try_files $uri =404;


Redirect www subdomain (optional)

Probably, you will want that visitors that access through www subdomain be redirected to the main domain, if this is your case comment out green lines and remove orange lines.

Enable cache (optional)

Enabling cache, you can improve pages load speed adn accept more simultaneous visits. To do it comment out blue lines and create the proper folder to store cache files:

$ sudo mkdir /var/cache/nginx
$ sudo chown -R www-data:root /var/cache/nginx

Enabling your new site

$ sudo ln -s /etc/nginx/sites-available/EXAMPLE.COM /etc/nginx/sites-enabled/

Setting up MySQL server

Use this command to get the message of the day, where you can find the MySQL root password:

$ cat /etc/motd.tail

Log in to your MySQL server:

$ mysql -u root -p

Create the database and user for “WordPress”:


Installing WordPress

From this point, you only need to do a normal WordPress installation. Start downloading the last WordPress version and extracting tar file:

$ cd /var/www/EXAMPLE.COM/html/
$ wget
$ tar xzvf latest.tar.gz
$ mv wordpress/* .
$ rm -rf wordpress

Ensure that you have the proper dependencies installed:

$ sudo apt-get install php5-gd libssh2-php

Create and edit the configuration file:

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

Set your database settings, save and close the file:

. . .
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'DB_NAME');

/** MySQL database username */

/** MySQL database password */
. . .

And finally ensure that files has correct permissions:

$ sudo chown www-data:www-data -R *
$ sudo find . -type d -exec chmod 775 {} \;
$ sudo find . -type f -exec chmod 664 {} \;



Este es un espacio para el debate. Dada la importancia de los comentarios como espacio de participación, te pedimos por favor que leas detenidamente nuestras normas de participación.

5 respuestas para “How to deploy a WordPress blog into DigitalOcean hosting

Jamil Ahmed

Hello Elias, You did an excellent post on how to deploy a WordPress blog into DigitalOcean hosting. DigitalOcean’s cloud infrastructure is one of the most reliable in the industry. Websites hosted on DigitalOcean rarely go down. Through the Cloudways Cloud Platform, you get fully managed DigitalOcean cloud infrastructure.

Elías R.M.

Thank you Jamil, I’ll take a look to Cloudways.


Jamil Ahmed

Welcome Elias 🙂


Very informative article. Overall a nice guide but it is somewhat complicated for beginners.
Thanks for sharing

Elías R.M.

Thank you very much Shivani.

I am working on a simpler version, probably using scripts that simplify the process.


Leave a Reply

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