Move Wordpress site to another server with different domain name

Most of the time, we move live site to a testing environment to do some tests. Here is how to do it. 

Assumptions:
         1. Source and Target servers are using linux ubuntu OS.
         2. Webserver settings are already configured.


 Steps:

 Source Server:
1. Create a compressed copy of your website code.

tar -zcvf <location_of_target_file>.tar.gz <website_code>

eg. 
tar -zcvf /tmp/bacukup.tar.gz /home/avtar/www/* 

 2. Take database backup. Here I am assuming you are using mysql on same server as database.

 mysqldump -h <hostname>  -uroot  -p ><location_of_backup_file>

 eg. 
 mysqldump -h localhost -u root -p wp_db>/tmp/db_backup.sql

3. Compress the db backup file.

tar -zcvf  <target_file_name>.tar.gz <db_backupfile_location>

eg. 
tar -zcvf /tmp/db_backup.tar.gz /tmp/db_backup.sql

4. Transfer both the files to target system. You can do it with scp. Here, I have already setup ssh access to target system from source. 

scp <source_file_location_and_name> <user@target_system>:<target_location_and_file_name>

eg.
scp /tmp/bacukup.tar.gz avtar@test.domain.com:/tmp/backup.tar.gz

5. Untar the files and move code to the appropriate location where your server is pointing.

Target:
tar -zxvf <file_location>
mv <folder path to move>  <target_location>

eg.
tar -zxvf /tmp/bacukup.tar.gz
mv /tmp/home/avtar/www/* /home/avtar/www/*

6. Import mysql database to the target database.
7. After everything setup, open the wp-config.php file in code and setup DB credentials.
8. Connect to mysql and run the following queries by changing domain names.

Update wp_options set option_value = 'http://new_domain.com' where option_name in ('home','siteurl');

If you have enabled ssl certificate using "Wordpress https" plugin, then you might be redirected to original site whenever you open wp-admin page on your site. To resolve that you can execute following statement.
Update wp_options set option_value = 'https://new_domain.com' where option_name in (wordpress-https_ssl_host');

You can check by opening website and admin panel. But wordpress has many old links stored in DB. It is very difficult to update those links with DB updates as wordpress stores serializable contents. To update that I always use a plugin. 

9. Goto plugins folders in website code and download the following plugin. 
https://wordpress.org/plugins/velvet-blues-update-urls/
if you have given FTP access to the website then you can skip this step and add this plugin from admin panel also.

Now open the admin panel and enable this plugin.

10. After enabling this plugin goto admin panel-->tools-->update urls.
Update all type of urls from old to new. Remember to keep http and https both as they were before.

Warning: It will not update urls in your plugin settings if they are using custom tables.

Your websit is ready. 




Comments

Popular posts from this blog

MySQL 5.7 cluster with Galera on RedHat 7.4

Restore single database from full Xtrabackup backup

MySQL default Password