Lipat Bahay - Moving a Simple Drupal Site from One Server to Another via SSH

Category
Truck movers. Workers delivering boxes.

This transfer of Drupal site is when changing a web host company. The same process when transferring to a machine within the same web host but do not include the server configuration.

Back to top

From the Origin Server

Go to Drupal's folder /sites/default/ then open the settings.php file.

To open: sudo nano settings.php

Scroll down to database settings and copy the following:

  • origin_database_name
  • origin_database_user
  • origin_database_password

Go inside backups folder of the home directory, mkdir backups if none.

Create database backup:
mysqldump -u origin_database_user origin_database_name -p > database_backup_name.sql

Enter the origin_database_password when asked.

Create file backup:
tar -czvf file_backup_name.tar.gz /directory/path/of/Drupal/site/

Copy database_backup_name.sql and file_backup_name.tar.gz to the destination server using scp command. Here are the instructions on how to copy files via scp command.

Back to top

To the Destination Server

Create new database, take note of destination_database_name, destination_database_user, destination_database_password.

Import database_backup_name.sql
mysql -u destination_database_user -p -D destination_database_name < database_backup_name.sql

Enter the destination_database_password when asked.

Uncompress the files to backups folder
tar -xf file_backup_name.tar.gz
cd file_backup_name/Drupal...folder/sites/default

Change permission to move and edit the file
chmod 777 settings.php
cd file_backup_name/Drupal...folder/

Move the files to public Drupal directory
sudo mv * /path/to/new/Drupal/site/
sudo mv .htaccess /path/to/new/Drupal/site/

Edit the settings
cd /path/to/new/Drupal/site/
sudo nano settings.php

Scroll down to the database array and replace the origin credentials with the appropriate destination credentials.

  • From origin_database_name to destination_database_name
  • From origin_database_user to destination_database_user
  • From origin_database_password to destination_database_password

Revert permission to non-writable after saving the file
sudo chmod 444 settings.php

Done.

Back to top