Monday, February 22, 2016

Wordpress Multiside migration


Moving or migrating a WordPress Multisite can be frustating. If you don't know how to move it safely, your site can break along the way. Either the database, the settings, or both. Let me share you how to migrate WordPress Multisite safely without breaking anything.
In this tutorial, I will explain how to moving WordPress Multisite from live server to localhost with an example case: we will move WordPress Multisite from http://example.com to http://localhost/example.
In this case, the live server is using cPanel and the localhost is running on XAMPP.
  1. First, we have to copy all WordPress files from live server. You can download it all via FTP. Or if you prefer to download it directly from cPanel, you can go to 'File Manager' in your cPanel. Navigate to public_html. Select all files, click 'Compress'. Download the compressed file. Don't forget to delete the compressed file from live server after you finish download it.
  2. Now we need to copy the database. Go to cPanel's phpMyAdmin. Export the entire database of WordPress Multisite that we want to move.
  3. Create new folder 'example' in localhost folder (\xampp\htdocs\). Extract the compressed file that we have downloaded in step 1 to the folder 'example'. Now we have the WordPress files inside the folder 'example'.
  4. Create new database in the local phpMyAdmin. Visit http://localhost/phpmyadmin/. For this tutorial, I will name it 'exampledb'. Import database that we have exported from live site in step 2.
  5. Open .htaccess in the root folder (\xampp\htdocs\example\). Edit RewriteBase into:
    RewriteBase /example/
  6. Open wp-config.php. Change database information to:
    /** The name of the database for WordPress */
    define('DB_NAME', 'exampledb');
    
    /** MySQL database username */
    define('DB_USER', 'root');
    
    /** MySQL database password */
    define('DB_PASSWORD', '');
    
    /** MySQL hostname */
    define('DB_HOST', 'localhost');
    Also, edit these two lines to:
    /* Multisite */
    
    define('DOMAIN_CURRENT_SITE', 'localhost');
    define('PATH_CURRENT_SITE', '/example/');
  7. After that, we need to change all urls. DO NOT manually search and replace everything. WordPress database use data serialization. Any mistakes can make your site cannot work properly. You have to use tools or scripts to search and replace database. As recommended on WordPress, we will use Search and Replace Database script from interconnectit.com. Download that script (We use V 2.1.0 Stable).
  8. Extract that script's .zip file. You will see .php file inside. For security reason, rename it to difficult name. Something like: w39opzzzzzzzt.php. Make it hard to be guessed!
  9. Copy it to the root folder.
  10. Run the script by visiting http://localhost/example/w39opzzzzzzzt.php (or your choosen file name in step 8).
  11. Check 'Pre-populate the DB values form with the ones used in wp-config? It is possible to edit them later.' Click 'submit'.
  12. Click 'Submit DB details'.
  13. Select all tables. Leave 'Leave GUID column unchanged?' unchecked. Click 'Continue'.
  14. Search for http://example.com, replace with http://localhost/example. Click 'Submit Search string'.
  15. Don't forget to DELETE Search and Replace Database script .php file as soon as you finish use it!! It is very very important for security reason. You don't want someone to use it and break your site, do you? :)
  16. Go to database (http://localhost/phpmyadmin/).
  17. Check wp_site table (or yourtableprefix_site). Change domain, from example.com to localhost. And path, from / to /example/
  18. Also change domain and path in wp_blogs table (or yourtableprefix_blogs).
  19. Now, visit the site in http://localhost/example. You should see it running smoothly without problem. :)

No comments:

Post a Comment