I came across a project that taught me how to migrate a wordpress website from one server to another, after doing research I managed to successfully migrate my website from the old server to the new one.

In this article I will be making an assumption that you are using digital ocean as your Infrastructure provider and you have already installed the following software’s on your new server.

  1. Create a server in digital ocean
  2. Install Apache
  3. Install php and its modules
  4. Install Mysql or MariaDB
  5. Harden Apache, enable rewrite module and enable SSL module


The first step to acquire an SSL certificate for your new server is to install certbot software. Certbot is in very active development, so the Certbot packages provided by Ubuntu tend to be outdated. However, the Certbot developers maintain a Ubuntu software repository with up-to-date versions, so we’ll use that repository instead.

First we are going to add the repository of certbot

sudo add-apt-repository ppa:certbot/certbot

and press ENTER to accept.

Install Certbot’s Apache package with apt:

sudo apt install python-certbot-apache

Certbot is now ready to use, but in order for it to configure SSL for Apache, we need to verify some of Apache’s configuration.

The next step is to Create an API token in DigitalOcean (https://cloud.digitalocean.com/account/api/tokens?)

Click on generate new token to get you token, once generated copy the token and paste it on your not pad.

Login the server, and create a file anywhere you like. for the tutorials we will create a file in /home/certbot/gititalocean.ini and put in this:

dns_digitalocean_token = your_digitalocean_token_copied_from_above_step

Note: in your new server there will be only the home folder, you will have to create the folder certbot

The next step would be to install the Digital Ocean DNS plugin for Certbot/Letsencrypt on your server. This can be achivied by typing the following command:

pip3 install certbot-dns-digitalocean

Note: If you don’t have pip3 installed, you can install it by typing sudo apt install python3-pip

Finally, generate your SSL. If you have an existing SSL you can delete it by typing the command

sudo certbot delete

then select the certificate/domain you wanna delete

To generate the SSL, enter

sudo certbot certonly –dns-digitalocean –dns-digitalocean-credentials /home/certbot/gititalocean.ini –server https://acme v02.api.letsencrypt.org/directory -d example.com -d *.example.com

Note: copy the aboce code as one sentence


After Installing the SSL certificate in the new server, the next step is to migrate the website from the old server to the new server. The first step would be to zip your website directory. Lets assume that your website directory is in /var/www/html. In this case you would zip html which contains all your website data. Transferring the website can be accomplished by typing the below codes. We are going to use acronym’s where S = server  


scp -pr /var/www/html root@THE-IP-OF-S2:/var/www/DOMAIN-NAME-OF-S1-WEBSITE


scp -pr /var/www/html.zip root@

Note: it is advisable to zip your directories for fast transfer of data 


The next step would be to migrate your website configuration file which can be achieved by typing the following commands:

# scp -p /etc/apache2/sites-available/default.conf root@ip of d2:/etc/apache2/sites-available/default.con

Note: copy the aboce code as one sentence


The last step is to transfer the database of the website from the old server to the new server

The first step would be to make the copy of the database by using the mysqldump command

mysqldump -u username -p database_to_backup > backup_name.sql

After dumping the database the next step is to move the database from the old server to the new server by typing the following commands.

scp -pr /var/www/html root@the-ip-of-S2:/var/www/domain-name-of-S1-website


scp -pr /root/folder/backup_name.sql root@

Finally you need to Restore the backed up database on your new server database.

login – mysql -u username -p

create a new database

CREATE DATABASE database_name;

mysql -u username -p database_name < backup_name.sql

Leave a Reply

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