Cloud vs Shared Hosting, For Ubuntu 14.04 LTS
One of the most noticeable advantages of cloud servers in general is resource availability, meaning you always get what you pay for. They are reliable, stable and efficient when handling websites and blogs with high traffic. While shared hosting is slightly cheaper, it simply cannot promise stable resource availability as these websites and blogs precisely because they are shared. This tutorial aims to help you through a migration of a WordPress blog/website. The process should take a few hours and should help you avoid any downtime.
It is good practice to have data backed up before carrying out any changes to the system. In this case, a full file backup along with MySQL backup is required. Hosting companies usually provide controlling software which helps make server management a bit more intuitive. We’ll be using cPanel for our example.
To create a file backup, simply copy folder “wp-contents” from your server to a secure place (your desktop, external HDD, or even a USB stick). During migration you will need to upload it to a cloud server with no changes to your blog structure. Just archive the folder (export to a zip file), then download it as soon as it’s generated. This way it’s less likely the file will get corrupted. Easy as that.
Another part of this section is to perform a database backup which can also be done quite easily using GUI software:
From cPanel, go to “Backup Wizard > MySQL Databases“.
MySQL databases are usually exported in the *.sql.gz format.
Export the back up as mysql_backup.sql.gz to the same location as your “wp-contents” archive.
LAMP stack installed on the new server.
Once your virtual private server is set up, you can start adding WordPress dependencies to form a LAMP stack:
- PHP Framework
- web server (we’re using Apache as the most common for WordPress builds)
Now everything is ready, you’ll need to install WordPress onto the server. The WordPress download section will link to the latest version from the main site, and installation is fairly straight forward. If you do have any problems there are plenty of guides online dedicated to setting up WordPress. This guide will only cover the migration process, but we might add one at a later date.
Configuring Virtual Host
You’ll need a new apache virtual host to handle the WordPress blog after you migrate the files.
To create a fresh file use the command:
# nano /etc/apache2/sites-available/example.com
Add a virtual host (use your own details instead of example.com and username).
Let’s break down what you’re doing:
Every <VirtualHost></VirtualHost> black, signifies a separate virtual server.
The number next to the opening of each block *:XX indicates the port number that Apache will
be listed on.
ServerName is simply your domain name
DocumentRoot is the location for toe the Root of your WordPress directory.
Redirect permanent / http://example.com/
Use the Apache utility ‘a2ensite’ to flip the on-switch for the created virtual server. It will use the new configuration and tell Apache to listen for your domain.
# a2ensite example.com
Any changes in server configuration will require you to reload the server to apply those changes. So reload it now:
# service apache2 reload
The actual migration — upload MySQL database and file contents to the VPS
WordPress is now set on the cloud server meaning that all the data from the old hosting environment can be moved over. First, upload the MySQL backup and web-content archives.
SCP is used to copy files among hosts over the network.
SSH protocol is used for transfers to apply a layer of security and authentication to the process. While it might sound complicated, SCP is easy to use and a very handy tool. To transfer a file you will need to input the file location on the hard drive and the recipient server details for the file transfer.
Use this example as a template for the command you’ll need to run, you’ll need to execute it on the device storing your blog files to transfer it to the cloud server. Remember to keep a colon (:) at the end of the command:
# scp ~/Desktop/mysql_backup.sql.gz username@server_ip_address:
# scp ~/Desktop/wp-content.zip username@server_ip_address:
Restoring the database
You’ll need to log in to the server and define database_user, database_name with your details for this command in order to restore the database.
# mysql -h localhost -u database_user -p database_name < mysql_backup.sql.gz
You may need to specify a few other things in the command so let’s look at it a bit closer:
-h flag specifies the host address: leave it as localhost if the database is on the same VPS
-u flag is for the database username: database_user that you always need to specify
-p means that you will be required to provide in a password once prompted.
The last part is simply one name of the database backup file.
Once you execute this command, you will need to provide a password for the database user. After that the database backup contents will be imported to the new database_name on the VPS.
Restoring wp-content files
To restore your WordPress site to its pre-migration state, you’ll need to extract the zip archive you created with the unzip command.
That should extract and merge the stored content – ie themes, images, plugins etc with the wp-content structure – on your vps server.
# unzip wp-content.zip -d /var/www/
Verifying the results
You’ll need to run a few tests to make sure everything is running smoothly on the new server.
If you don’t come across any errors during this stage you should be able to migrate the site with no downtime at all.
First, upload your hosts file using this command line:
# nano /etc/hosts
Add this line to the end of the hosts file on your local computer
You’ll know that it’s working as it should if visiting example.com, will point you to your new server, but this should work only for your local machine. This will make testing a lot safer.
Do not forget to replace server-ip-address by the actual ip address of your VPS. Next, clear your DNS cache to apply settings of a hosts file configuration:
# service nscd restart
At this point everything should be working from your local machine. Once you type in your blog’s address, like example.com in the browser, you should see your blog as if it was never moved. If something is wrong, carefully go through the instructions again and perform some troubleshooting. Once you’re happy with the test, return the hosts file to its default state.
DNS settings renewal
The last step – you’ll need to update DNS settings via your domain registrar.
The ip of your new server goes in the A record
DNS always takes a while to update (up to 24h) during that time your site will continue to be served from your OLD hosting provider, so make sure you don’t cancel prematurely or don’t rush in to changing your new server settings if the site suddenly goes down.
This article was brought to you by VPS.net, for dedicated server hosting, cloud servers and 24/7 support visit our site here vps.net