If you have ever tried to migrate your website from one host to another, I’m sure you will say the process is extremely tedious and a pain in the rear. Sure there are many technologies in the market that can help you with the same but to avoid all that nuisance.
If you don’t have digitalocean account, you can create one. Sign up using this link and you will get $10 in your account. GET $10 in your Digitalocean account now.
In this tutorial article I am going to walk you through the whole process on how to migrate your WordPress site from a shared hosting like Bluehost or Hostgator to Digitalocean hosting. Many people are unable to do so because they find it hard or kind of more technical. But it’s really not that much! I recently migrated this site from Bluehost shared hosting to digitalocean.com and it happened so like a charm. Bluehost is one of the best hosting service I have seen in low price but there were some drawbacks in Bluehost which made me shift to Digitalocean VPS.
This article is newbie friendly, So even if you are not familiar with linux or command terminal ! don’t worry. I have tried to explain every small things.
If you are looking for only fresh wordpress installation on digitalocean then you only have to follow Step 2.
Why you need to migrate from Bluehost to Digitalocean ?
There could be many reasons, but i will make it quick.
- Root access : You won’t get root access in shared hosting while you will have complete access of root which gives you more control over your vps system.
- Security : In shared hosting they have preset firewall settinbg and security, whereas in Digitalocean you have to setup everything.
- GUI Management : Hosting like bluehost, hostgator provides cpanel which makes your work easy, In Digitalocean you will have no cpanel, which means you have to work from command terminal itself.
- Support : Bluehost provides absolutely reliable support, Digitalocean have no such good support, i recently opened ticket in digitalocean about database problem and i got reply from one of member from support staff, the answer was stupid i could say. All they do is give us link which “MAY” help us.
So i hope you know now what to choose, if you are having high traffic and want to go for vps then i would suggest you to go for digitalocean.
So you have decided to migrate from shared hosting to digitalocean ? If yes, read on.
Remember the things you need on your new hosting is/will always remain same :
Why wp-content folder ? Because it has files of our themes, plugins, and all our images stored in uploads folder. So it’s must to take backup of it.
#1 : Backup your wp-content folder
First of all let’s backup folder “wp-content” , To do that we need to use FTP application such as Filezilla. Download and Install filezilla program.
After Installing when you open filezilla program, you will get option to put “Hostname” “Username” “Password” and Port.
As we are taking backup now, we would first login to our shared hosting.
If you don’t know where to get username and password of your FTP, login to your hosting website then go to cpanel and look for “FTP” , you will get it there. For those who don’t understand filezilla structure. here look at picture.
Once you logged in your filezilla you will see all your files which are hosted on your wordpress site. You should move to public_html folder and you will see your wordpress files including configure file and other folders, Just drag the folder named “wp-content” from right side to left side ( your computer ) to download it. Once you do it, you will see process at the bottom of your filezilla. I hope you did it.
Now we got one part of backup, Now we need the database backup.
How to get Shared hosting Database backup ?
There are many many ways to have database backup, you can do this with many plugins. But in tutorial i will go with “phpmyadmin”.
Of course you are familiar with bluehost cpanel as you are using it, move to option phpmyadmin icon from cpanel. It will prompt for password, enter it and now you are into phpmyadmin.
Select the database you which is connected to your wordpress site, click on it. And then click on “Export” button like below
Once you clicked on it, you will get option to click on “GO” click on it. Just make sure from dropdown box there a option “SQL” is select. When you click on GO, download will begin. So it’s all for download SQL Database of your wordpress site.
Method 2 : In this method, we can use feature available from hosting company to get backup. This is much easier, In just clicks you will have your Database downloaded on your computer.
Now you have all you need to migrare site. So you can now disconnect the filezilla.
#2 : Setup Digitalocean Droplet
Creating digitalocean droplet is quite easy, you just have to enter name and Options too choose while creating it.
I would suggest to use LEMP One click Install ! we will going to use it.
In the region option, you can choose from where you will have traffic. If your traffic region is from europe, better to choose amsterdam. You can enable “Private networking” option and then click on “Create Droplet”. Your droplet will be ready in minute.
As we already installed LEMP, it has installed Linux, nginx, Mysql, Php. Next target is to install wordpress on your server. Follow below me to install wordpress.
If you are on windows ( mostly of you are ) then you will need tool called “putty” ! If you don’t have it, Just download it from the link i have given and install it.
Once you have installed it, Open it and then you will see it like this.
While creating your droplet, you have get your IP address of your droplet.
In Host name enter IP address, and remain port as 22 ! then click on “open” and you will be prompted for username, enter “root” and then enter password you received on your mail and then Hit enter. Now you are successfully logged in.
When you log in, you will see message displayed on command terminal, HERE you will your MySQL password default generated when you used one click LEMP installation. So just write it down on your notepad file of your computer. It’s important.
If you don’t get the mysql password, then you can get it from this path : /etc/motd.tail , just use this file via cat or vim or nano. So you can get password of mysql from that path.
All set !? Yes ? then good, go below ! If not getting anything, comment below or contact me via contact form.
So now we are successfully logged in to our digitalocean system.
First thing we need to do is create mysql database in our system. Let’s do it.
You will be prompted for the password ! So here you have to paste that mysql generated password which we just noted down in notepad. Now it’s time to create Database. Create it now !
Change DATABASE_NAME to whatever name you want to set to your wp database. Now we should create user, here we do it
Here you need to replace “USERNAME” to username you want to create and change “password” to whatever password you prefer. Once you done it, Hit enter.
This will link the database and user we created.
To make detect the changes we need to run following command
Now we are again back to command prompt.
Next we need to Download and Install wordpress on our digitalocean server. So let’s do it
This will download the latest version of wordpress from wordpress.org site and stored in our digitalocean system. Now as it’s compressed, we need to extract it, It can be perform with following command. It will create wordpress directory.
It’s better to have latest versions on our server ! so we should run following command to download the packages from repositories and update them for latest info with their dependencies.
It’s now time to setup our wordpress files. We already have extracted our wordpress files in previous command. So we could now switch to wordpress folder by using following command.
We have got wp config sample file which is good, so let’s just make a copy of it where we can make our database, username and such settings. Use command
Now we have to edit wp-config.php file, so that we can add our database name, username, and password into it. we can use VIM editor or Nano, you can use whatever you comfortable with. I am going to use nano editor for this tutorial.
After hitting enter from previous command, you will be into file editing mode, use your keys from keyboard to change cursor position. Change Database name and username and password as i shown below.
Simply edit these values which i marked in different color. Then save this file ! You can do it by CTRL + X , and then press “Y” for yes. Now you are again back in terminal.
Now we are going to create Document root for our website. Let’s create directory for that.
We already have files on our root of server ! so we need to move it now from that path to our document root with this command.
Now go to folder of html where we actually copied all wordpress files.
www-data perform with Nginx web-server. So we will change permission with command. It will give necessary ownership.
We should also need to create folder for our images, so let’s create “uploads” folder Where we will later upload our all images.
This uploads folder don’t have link between www-data, let’s do it with
This next few command is going to bit techie but i would make it quick. Just follow me
It will copy the file “default” and make new file “wordpress” where we going to edit some necessary things which will helpful to run our site.
As we have copied file named “wordpress” , Edit it with nano editor.
Few things will required to change, I have highlighted that part as shown below
Things we need to change :
Change root pointing path to /var/www/html where we have placed our wordpress files.
Enter your DOMAIN.COM instead of EXAMPLE.COM
Off the line try_files $uri $uri/ =404; and Add new line as ON stat.
After making this changes, save the file with CTRL + X and then press “Y” for yes.
In order to activate our new file we can run the follow command
And now remove the old file
All done. To make changes work, we should restart the nginx server. You can do it with following command
Now everything is successfully completed. You can install wordpress now on your site. To do so, Copy your IP address you get from digitalocean server and Paste it in your browser. You will be prompted to WordPress Installation page. Fill out all information
After done with it, Simply login to your wordpress dashboard. Currently you have new fresh wordpress installed. You can access your site from IP, but not from domain name !!! that’s not good. So let’s just do it.
Login to your domain registrar and add A record to Digitalocean IP address and save it. It may take 5-10 minutes to propagate, sometimes upto 24 hours but for me it always around 1-2 minutes. btw i am using cloudflare, so i don’t need domain registrar for that. If you are also using cloudflare then change in DNS settings and add A record pointing to IP.
You may notice that your site still opening with IP only, yeah ! because you didn’t tell your wordpress which URL to load, so go to settings of your wordpress dashboard and then in two boxes of URL of your site, enter your website URL. You can use whatever you prefer. without www and also with www. It’s upto you.
When you hit save, you will be logged out and now you can login with username and password ! now you can access your site with domainname.com not with IP. But now your site completely changed. You are having new default theme, default plugins. No posts, No pages. Don’t worry we will do it in minutes.
#3 : Uploading WP-CONTENT Folder to Digitalocean
Jump to FTP program Filezilla and login to your digitalocean server. In hostname enter IP address, In username use root, and in password you can enter the password you received from digitalocean in your mail. Port should be 22. I hope you successfully logged in now.
The Database and folders wp-content and uploads, we are going to upload to server by simple drag and drop.
First let’s upload folder. In digitalocean server, go to /var/www/html/wp-content and drag your wp-content folder content over there. It may take few minutes depends on your wp-content folder size.
Or if you think it’s taking long time, you could compress your wp-content folder content ( make it .zip )and drag it over to your DO server wp-content folder. All you need to do it just extract wp-content folder.
Go back to putty, login there and run this command to go to directory of wp-content
To extract we need to install which can extract.
Now to unzip wp-content file, run this command
Your all content are now extracted with all images.
#4 : Restore your Database backup in Digitalocean :
To restore your database, you need to drag .SQL file you downloaded in step 1 to root of your digitalocean. We need to import this database to the database we have created previously. To do so use this command :
NEWDATABASENAME : Change this to the name of database you have created in Digitalocean
OLDDATABASE.SQL : The database you took backup from shared hosting and uploaded in root of your digitalocean.
As you run this command, you will be asked for mysql password, enter the ROOT password of your mysql. All done.
Now you just reload the wordpress dashboard and check you got your all posts, pages, plugins and themes back. If yes then congratulations ! you have successfully migrated site.
No ?? sad !
If you can’t see your posts and all back then don’t worry, That’s because of we didn’t add Table prefix in wordpress wp-config.php file. Let’s do it. While you were taking backup from mysql you may have seen wp_abcd_ or something like that. Not normal wp_posts. So we need to add those prefix into our wp-config.php file.
Or else you can navigate to it from FTP software and then right click on wp-config.php and click “edit”
Once you are in editor, go below in file and find “$table_prefix” and just after it, add the prefix.
I hope you added the prefix and now just save the file and exit. Reload the wordpress dashboard and now you can see your all posts, comments, themes, plugins restored.
This article can be applied to migration from hostgator to digitalocean as well.
Note : We could have used no-downtime method by adding digitalocean ip pointing to yourdomain.com in your computer hosts file which is located in C:\Windows\System32\drivers\etc. With the help of hosts file we can tell our computer to pretend that the mention IP is from specific domain while for others it will be normal. But personally i do not recommend this method.
I guess this guide helped you. If you have any further questions then you can contact me via contact form or comment below. I will be happy to help.