Aug 13

Issues and solutions for moving WordPress based applications from one hosting to another

Just moving the Training and Education site http://SitesTree.com to a different hosting i.e. from a reseller hosting to a Cloud Hosting (no, it is not AWS or Azure or Bluemix cloud, just the as usual cloud hosting provided by some regular hosting provider. ) . Just two cents on how this moving (WordPress) can be done.

http://sitestree.com is a Word-press based (saying this openly can be a security risk (at least, the novice hackers with this info will not have to do any work to find this out ) ).

The process is as usual:
Backup of all Files (Application Files as well as server files), backup of databases, also backup emails that have @sitestree.com address, backup of email forwarders. Usually, you can use the hosting control panel (such as WHM, Cpanel, Plesk) backup wizards (backup related options) both for DB and File Backups as well as email and email forwarders backup. The simplest approach can be, download using ftp client like Filezilla or use commands like SCP (scp command or related. SSL commands (scp) once exposed some security issues, please check the current status on that). And yes, if you were using Git and pushing through Git to your server (with Continuous Integration or not, with Github or similar or not), git fetch/pull/merge and creating a copy (see if git export to get only the latest code without git related folders will help or not) - all could work.

Then upload the files to your new server using Filezilla/or git commands (with or without CI) and/or passing through GitHub (to your new server) all can work. and/or using scp linux commands. rsync can be related.

Then moving (i.e. to new hosting) data through your new hosting Cpanel interface will work. Use the .sql file. I faced some syntax and version compatibility issues (though apparently at that point the MySQL version on the new hosting was not known to me and I could not find the information easily. tried to use MySQL4.0 syntax, did not work).

Hence, I first did, used the sql for structure only and then used the SQL for data upload. PhpMyAdmin can be handy here. Or MySQL command line can also be great (I use this all the time) along with MySQL administration tools such as MySQL Workbench or MySQL Query Browser (old) will also help. Apparently, the datatype longtext was the issue in my case.

When I created the backup SQL script, I did avoid foreign key check, used if not exist for table creation, and truncate before data insertion. Also, for insert statements, used the option to put multiple data rows for one insert SQL command. If you are using PHPMyAdmin for the import of SQL, you can use the import option in PHPMyAdmin. You might need to write one line in the sql file - at the top -

use your_new_db_name;

If you are using solely command line and even for all MySQL operations:
mysqldump command can be used to create database dump.
mysql command can be used to restore the database in the new server. Beforing restoring, you might need to replace site URLs and/or Home URLs/Paths.

You will also need to create db-user and password as well as assign permissions to this user to the database (in the new server). Sure, I did. Then you will need to change files such as wp-config.php, wp-load.php, wp-settings.php or similar most importantly wp-config.php and wp-settings.php. Change the database related configurations there (wp-config.php). Provide the path (absolute file location) to your site in the new server (wp-config.php). Sometimes, you might also need to change config files for some of the plugins (i had to do this for a security plugins). Ideally, you need to scan through all files and replace the application path as appropriate. You can use an IDE for that (PhpStorm, Sublime, NetBeansIDE or similar) (i.e. search and replace). Linux commands can also be great for the purpose.

For me one issues, was with Cache. When you create the backup, you might want to turn off caching before you create the backup. You might as well clear/delete cache (cache files), before creating the backup. Otherwise, you might have to change cache related settings in the wp-settings.php file or in one another file (seems, I do not remember the file name right at this moment) (I was using a caching plugin).

Then you need to replace the old url with the new url in the database as well as in the config files (wp-config.php). You can use the Search-and-replace-db WordPress library (found on github for the purpose) for replacing URLs in the DB. Please use the dry run first (there is a button for Dry Run) - this will show all possible changes. if you are happy with the out come of the dry run then do the actual changes.

Or searching database through PhPMyAdmin and replacing will help. Or any other DB GUI Tool that you are using will help. Another, cool option can be, you can use Linux commands to search and replace in your SQL files (sed : https://www.computerhope.com/unix/used.htm).

Though, if you want to keep the same URL even after your move, you do not need to search and replace URLs in the db and config files.  Then for testing your new site: You can just put the new IP in the hosts file against the domain name. Then if you try in your browser with the same domain, this new site will load (it will take IP from your hosts file).

Once, everything looks good, you can change the DNS for your domain/URL and point to the DNS servers for this new hosting.

Skip to toolbar
dead