Migrate WordPress blog to digitalocean with nginx Migrate WordPress blog to digitalocean with nginx

Easiest Way to Migrate WordPress Blog to Digitalocean with Nginx

With this article on easiest way to Migrate WordPress blog to DigitalOcean with Nginx, you can do so much more with your website.

When it comes to hosting, I have seen many bloggers running behind VPS hosting and DigitalOcean is the one who is ruling the market.

If you are the one who is looking to migrate WordPress blog to Digitalocean then here I am sharing the easiest guide that I followed in order to migrate my WordPress blog to DigitalOcean from Bluehost cloud.

Migrate WordPress blog to digitalocean with nginx

But before that,

Why DigitalOcean is the best

  1. Best in price
  2. You get a base VPS which you can easily configure as per your wish
  3. Huge amount of choices for operating system
  4. Unlimited tutorials for almost everything
  5. Lowest ping time
  6. Superb performance
  7. Pay as per your usage
  8. Easy scaling
  9. You can choose the data center location as per your requirement
  10. Highly reliable as its cloud VPS

In order to know everything about Digitalocean, you can visit one of my post as for why digitalocean webhosting is better than others. It’s a complete review which contains all the features offered by DigitalOcean

How to migrate WordPress blog to Digitalocean with Nginx

backup wordpress

The first thing that you have to do is to make backup of two things

  1. Your “Wp-content” folder
  2. Your “database”

Steps to make Backup of Wp-content

In order to make backup of your “Wp-content” folder just follow the steps below

  1. Login to your hosting account and go to “cPanel”
  2. Click on “File manager”
  3. Then browse to your “Wp-content” folder and download it in.tar format
  4. Save the downloaded file of “Wp-content” on your PC

Steps to make Backup of your Database

  1. Login to your WordPress
  2. Install and activate “UpdraftPlus”
  3. Go to “settings” and then click on “UpdraftPlus Backups”
  4. You will get three options as “Backup”, “Restore” and “Clone”
  5. Click on “Backup” and on the next screen click on both check marks and click on “Backup Now”
  6. This will make the back up of your data
  7. Now click on “Existing Backups” tab and you will see the backup of your database
  8. Click on “database” and after the process completes, click on “Download to your computer”

Remember, do not change the file name at the time of downloading on your computer.

Creating Droplet on DigitalOcean

Create droplet

Now, log off everything and login to your DigitalOcean account and create a droplet by choosing Ubuntu 14.04.5 x64. Choose whatever plan you want and then click on “Create” button given at the bottom of the page. Wait for some time and you will get a mail which includes your username as “Root” and “Password”. Don’t worry the password you have got is one time password, you will have to change it when you access your console for the first time.

PS: – I have used Ubuntu 14.04.5 x64 because this version of Linux consist of all the required features and need less RAM to work smoothly.

Adding Domain and Configuring host records

Just log in your domain registrar account (mine was GoDaddy) and change the domain name servers to


Login to your DigitalOcean account and in front of your droplet you will see a down arrow, click on it and click on “Add a Domain”.

  1. In the box, just enter your domain and click on “Add Domain” button
  2. Now you will see “Create new record” Just below that choose “A” and enter your domain without “www” under HOSTNAME box. For example – techmozz.com
  3. Then click on next box, your IP will appear automatically and click on “Create Record button”.
  4. Now choose “A” again and enter “www” only
  5. Just click on the next box and it will take your IP automatically
  6. Then just click on Create Record

Now, just download and install “Putty” and “Filezilla” on your PC as with those you will be able to work on your server easily.

Configuring your VPS

Now, we will configure our VPS and I won’t go much deeper into it. What you have to do is. Just open “Putty” on your PC, enter your domain in the first box and click on “Open” at the bottom.

You will see the black screen, just for some seconds and it will ask for your Username, enter “root” as your username. Then enter the password you have got in your mail.

Now, the system will ask you to change the password so enter the same password that you have got in your mail first and press Enter, after that, enter your new password, press enter and then enter the new password again in order to confirm.

Install Nginx

install nginx

Nginx is always better than Apache. It’s twice faster than Apache and its very lite weighted hence your website works smoothly. Here is the Nginx wiki which will help you know each and everything about it.

Run the commands given below in order to install Nginx

apt-get update

apt-get install nginx

It will ask you for “Y/N” in between, so just enter “Y” and it will continue

As the process completes, open your browser and enter the IP/domain. You will see a page as “Welcome to Nginx” which means you have done it right.

Install MySQL

Given below commands will install and configure MySQL so run them one by one:

apt-get install mysql-server

After running the command above you will be asked to configure MySQL root password so just enter whatever password you want to have for your MySQL root user.

Now we will install MySQL data structure by running the command given below:


Next command will secure our MySQL installation:


The system will ask to change password of root which you have entered at the time of installing MySQL, so if you want you can change it else, just enter “N” and hit “Enter” then just press “Enter”

Install PHP

As we have got Nginx and MySQL installed on our system the next step is to install PHP. Here we are using PHP5-fpm. “FPM” stands for “FastCGI process manager” which will enhance the performance of your website. Just run the command given below in order to install “PHP5-fpm” and “Php5-mysql”.

apt-get install php5-fpm php5-mysql

Enter “y” when it ask for “y/n” in between the installation

Configure PHP

Actully, there is a security issue in PHP which we will have to fix, so follow the steps given below in order to make your server secure.

nano /etc/php5/fpm/php.ini

After executing the above command you will see that a file has been opened with some configuration. So here what you have to do is, just find the word “cgi.fix_pathinfo”.

By default it is written as:


Change it to:


Now, press “ctrl+x”, then “y” and then “Enter key”. This will save the changes you have made.

Now run the command :

service php5-fpm restart

and its done.

Configure Nginx server

Now, we will have to configure our Nginx server. So, we will open the configuration file and make changes it to. I have mentioned the “changes in “red” color” so make sure you follow them properly.

Remember, that some lines may vary in sequence so take care of that. Do not add one line twice else your Nginx wont run.

Open the configuration file by executing the command given below:

nano /etc/nginx/sites-available/default

As the file opens you will find the default codes as:

server {

listen 80 default_server;

listen [::]:80 default_server ipv6only=on;

root /usr/share/nginx/html;

index index.html index.htm;

server_name localhost;

location / {

try_files $uri $uri/ =404;



You have to make the changes as given below:

server {

listen 80 default_server;

listen [::]:80 default_server ipv6only=on;

root /usr/share/nginx/html;

index index.php index.html index.htm;

server_name server_domain_name_or_IP;

location / {

try_files $uri $uri/ =404;


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_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;



As its done, press “ctrl+x”,”y” and “Enter key”. Your changes have been saved.

Restart the Nginx by the given below command so that the changes have been made.

service nginx restart

Remember, you should get “ok” after executing the command above. If you get “fail” means you have done something wrong while configuring the file so tally out again.

With this we are done with our installation and server configuration part. Now we will move on to installing WordPress and get back our website live.

Installing WordPress

install wordpress

Now we will create our new database on MySQL along with our new user which our wordpress will use in order to manage.

Begin by logging in to MySQL:

mysql -u root -p

Enter the password for MySQL which you have configured while installing MySQL.

Now, we will create a new database. Remember that you can change you’re the details given in “red” as per your wish but make sure you save them somewhere on your PC.


Don’t forget to enter the (;) at the end. You can change the database name from wordpress” to anything you like.

Now we will make a new user and add password for it by executing the command below

CREATE USER wordpressuser@localhost IDENTIFIED BY 'password';

You can change “Wordpressuser” and “password” as pr your wish.

But make sure to note down MySQL “Database name”, “User name” and “password” in a notepad on your PC and save it as we will need them in sometime.

Now we will connect the Database and User by executing the command given below:

GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser@localhost;

In the above command you will have to use your “MySQL database name” in place of “Wordpress” and your “MySQL user name” in place of “wordpressuser”.

Run the command given below:



Download WordPress and Configure it

Now we will download wordpress.


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

Now, unzip the downloaded wordpress by executing the command below:

tar xzvf latest.tar.gz

In order to work well we need one more package of php so run the command below in order to install it:

apt-get updateapt-get install php5-gd libssh2-php

These two packages permits you to work with images and will manage installing updates and plugins securely.

Configure wordpress

Now we will configure our wordpress :

cd /wordpress  

Now we will configure “Wp-config-sample.php” file. The first thing that we will have to do is to copy the file with file name “Wp-config.php”. So execute the command given below

cp wp-config-sample.php wp-config.php

Now, open the new file and make changes:

nano wp-config.php

You will see that the wp-config file has been opened and now you will have to enter the details of your MySQL Database, Username and password in this file which you have created before.

Just make the changes to the “red” colored part:

// ** MySQL settings - You can get this info from your web host ** //

/** The name of the database for WordPress */

define(‘DB_NAME’, ‘wordpress‘);

/** MySQL database username */

define(‘DB_USER’, ‘wordpressuser‘);

/** MySQL database password */

define(‘DB_PASSWORD’, ‘password‘);

Now, press “ctrl+x”, “y” and Enter key, In order to save file.

Now we will copy the complete wordpress folder to our document root folder and assign the permission.

But before that we will have to make our directory, so run the command given below:

mkdir -p /var/www/html

Now copy the files to the newly created folder by executing the command given below:

rsync -avP ~/wordpress/ /var/www/html/

Now go inside the folder where we have copied our wordpress and make a folder for uploads

cd /var/www/html/mkdir wp-content/uploads

Now we will assign the permission to the wordpress user in order to manage the complete working of our wordpress by executing the command given below.

chown –R www-data:www-data /var/www/html/

Modify Nginx Server Block

Lets copy our server configuration to the correct location by running the command below:

cp /etc/nginx/sites-available/default /etc/nginx/sites-available/wordpress

Now we will make changes to our new file:

nano /etc/nginx/sites-available/wordpress

Make changes to the “red” texts only.

server {

listen 80 default_server;

listen [::]:80 default_server ipv6only=on;

root /var/www/html;

index index.php index.html index.htm;

server_name your_domain.com;

location / {

# try_files $uri $uri/ =404;

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;

include fastcgi_params;



Now press “ctrl+x”, “y” and Enter key in order to save the file.

Now lets activate the file that we have configured just now:

ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/

Now we will remove the old file as it may create some issue:

rm /etc/nginx/sites-enabled/default

We are done with our wordpress configuration as well

Just restart the services:

service nginx restart

service php5-fpm restart

Open your browser and enter your domain, clear the cache of your browser before.

You will see your wordpress installation page

So follow the steps below

  1. Fill site title
  2. Enter the same username of wordpress as it is, when your website was on old host
  3. Enter the same password as it is when your website was on old host
  4. Enter your email ID
  5. Click on install wordpress

Restoring your old website

Now we will bring back your website, so just follow the steps given below

Restoring Database

  1. Install and activate updraft plus plugin
  2. Go to “settings” and then to “Updraftplus backups”
  3. Now click on “restore” and then click on “Upload backup files”
  4. Click on “select files” and upload your database which you have saved from old host
  5. Put check mark only on the database option and continue the process.

The above steps will bring back all your posts, categories and other things but not your themes, plugins and images. So to bring back, you will have to upload your Wp-Content folder which you have downloaded from old hosting.

Restoring Wp-Content

Follow the steps below in order to upload

  1. Open filezilla software on your PC
  2. Enter your domain in first box, root in second, your VPS password in third and 22 in fourth and connect
  3. Now, go to “/” then “var” then “www” and then “html” folder
  4. Just drag and drop the wp-content zip which you have downloaded on “html” folder.

As the process completes, just go to putty and run the command

Cd /var/www/html

Rm –rf wp-content

Tar –zxvf wp-content.tar.gz

Chown –R www-data:www-data /var/www/html/

With this you have successfully migrated wordpress blog to DigitalOcean along with Nginx configuration.

I hope you liked this easy tutorial, Dont forget to share

  1. I must say you have high quality content here. Your website should go viral.
    You need initial boost only.
    Thanks for awesome Content

  2. Great work. You explained so well. 🙂 I sometimes imagine how we can write with such clarity. Anyway keep it up.

  3. Pingback: Homepage

Leave a Reply

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