There might be a dozen of reasons why migrating your existing Drupal (or any other CMS) website from one host to another. In today's article, I will share my experience migrating Drupal 7 from one host to another before upgrading to Drupal 8
In this guide, I will migrate Drupal 7 between two separate Linode VPS, at one there is Ubuntu 12.04 and php 5.5 version while at the other there is Ubuntu 16.04 and php 7 version.
Data copies or Backups
Let's start with setting up an environment on host 1 or existing VPS. First I'm going to create data copies for the public_html folder (After investigating folders structure and size, I learned that existing website is at the size of 3.5GB size - that's decent I guess for a more than 4 years and active website).
For seeing folder sizes on your Ubuntu machine, you can run the following command:
du -sh public_html
Now, let's prepare this folder for migrating to another host.
Run the following command to create a tar.gz archive for public_html folder
tar -czvf completebackup.tar.gz public_html
Making archive file with Putty
Depending on the size of your website it might be a lengthy process. Though for making a backup for my 3.5GB it took less than a minute. Awesome.
Now in order to make our backup file accessible via web (wget) let's move it to the public_html in backups folder, if you don't have a backups folder, create one with the following command:
sudo mkdir /srv/www/reinisfischer.com/public_html/backups
Now let us move completebackup.tar.gz to backups folder
mv completebackup.tar.gz public_html/backups
Great, let's move on.
Backup for MySql Database via SSH
If you have a relatively small database you might try to use MySQL database backup using phpmyadmin. My database is larger than 1GB and for this data migration I find it easier to transfer data using SSH
Now let's make the backup for our MySQL database, see How to export/import a MySQL database via SSH
Exporting a MySQL database
To export a MySQL database, you need to use the mysqldump command. Here is the full command for exporting your database:
mysqldump -uUSERNAME -p DATABASE > backup.sql
You will be prompted for a password - this is your MySQL user's password.
The MySQL database will be exported to a file named "backup.sql" in your current directory.
Now let's move this database to host 2 with wget
from host 2
sudo wget http://www.reinisfischer.com/backups/backup.sql
And now let's import it to MySQL on host
Importing a MySQL database
To import a MySQL database, you need to use the mysql command. Here is the full command:
mysql -uUSERNAME -p DATABASE < backup.sql
Again, you will be prompted for the password of your MySQL user.
The backup.sql is the name of the file that you are importing to your database. It must be in your current working directory
Host 2
Now let's transfer files from host 1 to host 2 server. On host to, make sure you are in the public_html folder
cd /srv/www/reinisfischer.com/public_html
Transfer and extract files using wget and tar
sudo wget http://www.reinisfischer.com/backups/completebackup.tar.gz sudo tar -zxvf completebackup.tar.gz
LEMP Server Ubuntu 12.04 for serving Drupal on Nginx
We are almost there. Now it is just a matter of some configuration and MySQL database import.
Now by default phpmyadmin allows uploading just up to 2MB size database. As I have 92MB I had to configure PHPMyAdmin to allow uploading more
How to configure phpMyAdmin upload directory
Restart FPM
sudo /etc/init.d/php7.0-fpm restart