Last year, I moved this blog from Blogger to WordPress. Last week, I moved this blog from shared hosting to VPS. It was a fun experience and interesting too.
Why I chose VPS (Virtual Private Server) :
- To have better control and ownership of blog (a VPS server is fully accessible through root/admin compared to a shared host).
- Ability to run various apps of own choice.
- To have an ongoing side project (my other blog is already on a VPS and I love maintaining it).
- To learn more about tweaking and configuring Linux VPS.
- Linux command line is fun!
There are several VPS providers out there and they mainly offer two kinds of services : managed and unmanaged. Managed means that there is full time support staff that can take care of your VPS (ensure it is always up, secure and up to date, install and configure various apps and so on) while unmanaged means you are your own support staff (which provides a kickass experience to learn if you can dedicate the time IMHO).
After analyzing the trend and volume of this blog’s traffic and frequency with which it is updated , I went with an unmanaged VPS by Digital Ocean (all the VPS resources like RAM, disk space and bandwidth can be upgraded anytime if needed to accommodate growth – that is another cool thing of having own VPS – complete flexibility).
Here is how I did it :
- Purchased a VPS plan and setup the VPS server with required web server software for WordPress (LEMP – Linux, Nginx, MySQL and PHP)
- Copied contents and database of WordPress blog from old host to this VPS
- Changed DNS settings at domain end and VPS end so that domain now points to new VPS.
Setting up LEMP stack on VPS :
Installing LEMP is simple, just login to the VPS as root and first update the repository (Ubuntu server is used here) :
Once all repositories are updated, install each of the components : Nginx, MySQL and PHP-Fast CGI . This is done by typing :
sudo apt-get install mysql-server
sudo apt-get install php5-cgi
Setting up PHP-Fast CGI to work with Nginx :
Once done, to setup Nginx and make sure it works with php-cgi, refer to this excellent article here.
So now the VPS is up and running as a webserver, it is time to setup Nginx virtual hosts configuration as well as a MySQL database.
Setting up Nginx vhosts :
Create a directory (assuming blog is example.com) and set appropriate ownership as well as permissions :
sudo chown -R www-data:www-data /srv/www/example.com/public_html
sudo chmod 755 /srv/www
This will serve as the document root or the blog root. Now to set up Nginx vhost :
Copy the basic vhost config found here.
Once done, save it and enable this Nginx vhost by creating a symlink :
Restart the Nginx server :
Setting up a MySQL database :
Assuming a database named mydb with user as “freedom” and password as “pass”, issue the following command to get to MySQL command prompt:
Then :
create user 'freedom' identified by 'pass';
grant all privileges on mydb.* to 'freedom';
exit
What this will do is create a new MySQL database, now all that is left is to copy the contents and the database from current (soon to be former) webhost to the new VPS. Reboot the VPS once all of this is done.
Moving from old host to VPS :
Moving a WordPress blog involves moving the content (posts, images, contents) and also the WordPress database which keeps them. A simple guide to this can be found here.
To copy the contents, login to old host using ssh and from there type :
This assumes that the old WordPress installation is residing at /srv/www/oldwebhostpath/example.com/public_html and the VPS where it is to be moved is at /srv/www/example.com/public_html
Finally, import the old WordPress database which say is copied to VPS and is now at /srv/www/example.com/db by :
mysql -u root -p mydb < /srv/www/example.com/db
Then edit the wp-config.php file on the new VPS so that username, database name and password match the ones given when they were created before. To make sure that newly moved blog would work and be accessible as before, it is useful to edit the local hosts file and add an entry for the VPS IP address so that it maps to the domain name.
This can be great when testing and checking if all posts, images as well as editing functions are available just like on old blog before DNS changes are done. Also, firewall can now be setup and be checked if functionality is affected or not. Here is a simple method to set up firewall on a Linux VPS.
The Finale:
Now that the blog is moved and tested so that everything looks ok, it is time to permanently change DNS settings from the domain end as well as from VPS end. Here is a good resource on how to set it up at both ends. Once these changes are done, all that is left is to wait for about 24 hours. During this time, the blog traffic will be served from either of the hosts and there will be essentially no downtime at all. After a while, the ping response will start displaying the new VPS IP address and this means DNS changes are in effect. All of the traffic is now reaching the VPS and not the old host.
To check the DNS progress, it can be useful to ping the domain name from different parts of the world. Online ping tools like ping.ms should suffice.
Phew!
I hope this was helpful and may save a few hours for you.
Some considerations when moving :
- Plan the move such that there is ample time to revert to old host should anything go wrong and needs to be fixed. (Couple of weeks before the hosting plan on old host expiring can be convenient instead of moving just a day before the plan expires).
- Don’t be in a hurry to change DNS, ensure everything on new VPS works well like before.
- Clarify with the new host regarding billing process and also other queries that may come up before changing DNS.
- Changing DNS during low traffic days/time interval can be useful in minimizing any unforeseen disruptions.
Some useful resources and references :
Copying files and directories between different Linux machines
Backing up and moving WordPress blog
Installing Nginx, MySQL and PHP-Fast CGI
Configuring Nginx to work with PHP-Fast CGI
Setting up Nginx virtual hosts
Changing DNS records when moving between hosts
One thought on “How I Moved From Shared Hosting To VPS”