Moving WordPress Multisite from Live Server to Localhost Safely

Written by
(Last Modified: 24 July 2016)

Wordpress logo
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 Search and Replace Database script (We use 'V 2.1.0 Stable' version for this tutorial). Update on 23 April 2016 - to make it clearer: on that script page, please scroll down until you see the red button 'Problems? Try v 2.1.0 STABLE'. Download the 'v 2.1.0 STABLE' version.
  8. Extract that script's .zip file. You will see a .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. 🙂

Is this tutorial helpful for you? Do you want to add something to make it better? or do you want to share your experience when moving WordPress Multisite?. Share it all in comment form below.

Written by Dhyayi Warapsari
3 December 2013 (Last Modified: 24 July 2016)
Category: , , , , , ,
Tag: , ,

47 Comments

Add new comment
  • Thanks alot!

    I have tried several tutorials, and this was the one who worked perfectly at first attempt 😀

    • Thank you, Steffan. I tried to create this tutorial as clear and straightforward as possible to prevent any headache. I based it on my own experiences which I too have experienced several failed attempts at first as well (doh! :-p).

      I am glad it is useful for you. 😀

  • In 7. 'we will use Search and Replace Database script from interconnectit.com. Download that script.', the links are broken… Were can this script to be found?

  • Sorry, its worked after google registration 🙂

  • Anonymous

    Great instruction, thanks a lot.
    But I got problem with opening the admin network page such as http://localhost/example/wp-admin/network
    "The page isn't redirecting properly" occurred.
    Can you help ?

    • Hi. Have you followed the instructions above step by step? If so, we can assume you have properly moved the site – and thus can move to other guessing as to why you get the redirecting problem. It can be caused by many reasons. As I don't know your site setup, I can't be sure now. We can start by these questions: Does the problem only occur on admin pages? Do you use https on the live site for those pages?

  • Anonymous

    Very nice. Clear instructions.

    Part I was doing wrong before was replacing the subdomain url as well. Also missed the site table.

    Cheers!

  • Hello Sir,
    Will this work for vice versa. I mean
    " Moving WordPress Multisite from Live Server to Localhost Safely".
    Thanks

    • Hi Priti,

      If you mean vice versa is, moving WordPress Multisite from localhost to live server, then yes, it basically works the same. You just need to change the settings accordingly (doing it vice versa from above tutorial). For example on step 6, instead of "define('DOMAIN_CURRENT_SITE', 'localhost')" – you change it to define('DOMAIN_CURRENT_SITE', 'yourdomain.com'); etc.

    • Hello,
      I tried your solution but showing error while replacing the url using Search and Replace Database script.

      While dry run the process, it shows this error,
      "The script encountered an error while running an AJAX request.If you are using your hosts file to map a domain try browsing via the IP address directly.If you are still running into problems we recommend trying the CLI script bundled with this package.See the README for details."

      Please provide me urgent reply.

      Thanks

    • Hello,
      I believe you are using the script version 3.0.0 BETA.
      As that is still beta, on tutorial above we are using the V 2.1.0 STABLE. You can download version 2.1.0 STABLE on the same page https://interconnectit.com/products/search-and-replace-for-wordpress-databases/, button link "Problems? Try v 2.1.0 STABLE" – under the V 3.0.0.

      Hope that help. Cheers.

    • Thanks for this.
      But everything I did fine. But I dont know why its saying "Error establishing a database connection".
      If there is some error in connection file then why it has replaced all url. I dnt know why this error is coming.

      Is there any hint for this.

    • Hi Priti,

      Have you read and followed above tutorial step by step carefully? If so, the problem most likely caused by the wrong database information you put on wp-config.php (step 6). Make sure you enter the correct database name, user, password, and hostname. Because you are doing it vice versa (from localhost to live server), you should check the database information on your live server.

  • Hi aurodigo
    great guide (y). easy to follow and easy to understand.
    but in my journey through this guide, i encounter same problem with Priti. i edit wp-config.php exactly like my database setting, but the error still ocured. is it possible the error come from difference in phpmyadmin version. my database exported from phpmyadmin ver 4.0 and i import it to my my current machine with phpmyadmin 4.3.

  • hi aurodigo.
    i already solved the problem with version difference in phpmyadmin. but the error "error establishing database connection" still occur. any thought about it? what other option that possibly could go wrong?

    • Hi Turjen,

      That error is very likely caused by wrong database information. Maybe typo, insufficient permission, etc. You can try to recreate new user and password to make sure. If you are very sure, nothing wrong with the database settings, you can check the solution here to test your MySQL server: http://www.wpbeginner.com/wp-tutorials/how-to-fix-the-error-establishing-a-database-connection-in-wordpress/. Hope that can help.

    • hi aurodigo.
      i have fix my problem. i want to share my solution for other that have sam eproblem.
      the solution is kind of simple one. my previous wordpress site lies in root directory and my new one i set on subfolder directory. this kind of thing can make wordpress to wreak havoc by error establishing database connection and error redirecting. if anyone want to move their wordpress site, make sure to put the wordpress site in the same level directory as the previous one, and if anyoen wnat to put it in diferent level of directory, make sure to change every row in database to same level directory. watch for table wp_blogs (if table prefix set to wp_). hope anyone doesn;t have same mistake like me.
      😀

    • Hi Turjen,

      Thank you for sharing the solution for your problem. Hope that can help others. 🙂

  • Hi Aurodigo! You’re likely to be my last chanche to get this thing done…. and not to throw my computer to the sea… 🙁
    I’ve tried almost everytihing I’ve found around the web, without result!

    I’ve followed your instructions, but what I get is a White Screen of death when I try to open the site.

    I’ve tried changin plugins folder name, but did not change anything.

    Any suggestion?

    Thanks,

    Francesco

    I’m using MAMP, and not XAMP.

    • Hi Francesco,

      As you may already know by reading many articles around the web, there are a lot of possible causes for the white screen of death. I understand it can be very frustrating to find it one by one.

      By any chance, can you login or access the admin pages? [your-site-url]/wp-admin/
      If you can login to the admin, try to check Appearance > Themes. Is there any error message there?

    • Hi, thanks for your prompt reply. Appreciate it. No, I cannot.

      When I try to access to yoganride.dev I can see:

      Index of /

      – yoganride.dev

      If I click on it, I get the white page.

      If I try to access the backend: yoganride.dev/yoganride.dev/wp-admin I get the same white page.

      If I tri to access the backend: yoganride.dev/wp-admin I get a basic 404 page not found.

      Hope this helps you to give me any suggestion about where to look for mistakes…

      Thank you,

      Francesco

    • Hi Aurodigo,

      Sorry, I left a reply a few days ago, but something on pubblication has not worked.
      I cannot access the backend. 🙁
      I’ve made new serveral attempt… and maybe I found out which can be the problem, and it might be quite similar to Turijen issue.

      On my live installation, the multisite I’d like to export lies under: publichtml/mysitefolder
      On my local installation, it is now under: htdocs/mysitefolder

      Can this be the problem?
      If yes, do you have an idea on how to fix?

      If no, do you have any suggestion on where to start to look for possible problems?

      I’ve refollowed several times your procedure, which completely make sense to me, but still I get a white page after search and replace procedure.

      Hope you can help,

      Thank you very much,

      Francesco

    • Hi Francesco,

      Reading your reply earlier (comment on 12 June above), maybe it is something to do with your localhost setup? either there is another index file other than wordpress default?, or your php memory limit, or maybe this article about an installing issue on MAMP can help you? http://premium.wpmudev.org/forums/topic/local-install-of-wpmu-using-mamp-mac

  • I recently had to do this for a site. The hardest part was search and replace which I ended up doing to the database with sublime. After much trial and error I got it to work. Your method was way more smooth. Just an FYI for anyone who runs into issues doing this on a mac with mamp where it says to to add localhost, don’t forget to add localhost:8888 to the search and replace, as well as wp_blogs and wp_sites. Obvious maybe, but it slowed me a bit. Bookmarked this page. Will use it often. Thanks!

  • Valen

    Hi There,

    Everything alright till I get to the script
    I donwloaded but it has more than one .php file and I don’t know which one to rename and move. I tried with the index.php but I get an internal server error if I try to run it. Any ideas?

    • Valen

      Ok, I follow the instructions on the script page and so far I did the replacements
      I get a 500 Error 🙁

    • Valen

      Another update (and this is my last because I dont know what else to do)
      Folliwing isntructions I deleted the Htaccess, I get now an Error stablishing database conection.
      If i access to localhost/example/wp-admin I get a reason for the error telling me that localhost/example could ot be fount at wp_blogs (I have checked the table and the localhost/example is correct there)
      No idea what else to do ._.

    • Hi Valen,

      I believe you downloaded the different version of the script. As stated on my tutorial above, we use the “V 2.1.0 Stable” version. Please visit the script page and scroll down until you see two red buttons which say ‘Download v 3.1.0’ and ‘Problems? Try v 2.1.0 STABLE’. Click the second button – ‘Problems? Try v 2.1.0 STABLE’.

      I just read your comment above again and have to point out that I never advise to delete .htaccess file – it’s an important file and should never be deleted. The only thing you have to do with the .htaccess is edit the RewriteBase. That’s all.

    • Valen

      Thanks for your reply 🙂
      I tried the procedure with the version you recommend and followed the steps.
      Still I get a Error stablishing database conection on the homepage.
      if I go to the WP-admin tells me he cantfind the site localhost/whatever and something about the table wp_blogs (same as before) the table is correct in the database so I have no idea what could be wrong.

    • Valen

      Ok!
      No the Wp-Blog table had still the old values 🙂
      Everything works smoth now, THANKS!!! (Really!)

      😀

  • Valen

    ._.
    I’m afraid this is the neverending story
    Site works for not permalinks, I tried to update the permalinks as usually after migration but the only way to make them work is on the simple set up http://localhost/example/?p=123 if I change it to the normal structure I get a 404 error.

    As far as I can see this can be related to the htaccess, my initial doc was:

    RewriteEngine On
    RewriteBase /example/
    RewriteRule ^index\.php$ – [L]

    # add a trailing slash to /wp-admin
    RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ – [L]
    RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
    RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
    RewriteRule . index.php [L]
    mod_gzip_on Yes

    # BEGIN WPSuperCache

    SetOutputFilter DEFLATE
    SetEnvIfNoCase Request_URI \
    \.(?:gif|jpe?g|png)$ no-gzip dont-vary

    ExpiresActive on
    ExpiresByType image/jpg “access 2 month”
    ExpiresByType image/gif “access 2 month”
    ExpiresByType image/jpeg “access 2 month”
    ExpiresByType image/png “access 2 month”
    ExpiresByType text/css “access 2 month”
    ExpiresByType application/x-javascript “access plus 2 month”
    ExpiresByType text/javascript “access plus 2 month”
    ExpiresByType application/javascript “access plus 2 month”
    ExpiresByType image/x-icon “access plus 12 month”
    ExpiresByType image/icon “access plus 12 month”
    ExpiresByType application/x-ico “access plus 12 month”
    ExpiresByType application/ico “access plus 12 month”

    # END WPSuperCache

    # BEGIN WordPress

    # END WordPress

    If I dont delete the # add a trailing slash to /wp-admin rule the site gives me a 500 Error so I did but I have no idea what could be causing the problem with the permalinks.

    Sorry fo bother you again!

    • Dear Valen,

      Are you sure that is the correct .htaccess? It seems you have made some changes and make it not work properly.
      For example: ‘RewriteEngine On’ until ‘RewriteRule . index.php [L]’ should be in between ‘# BEGIN WordPress’ and ‘# END WordPress’.
      Let’s start fresh from the .htaccess file from your live site that you know working fine. Then, all you need to do is change the RewriteBase as mentioned on step 5 on my tutorial above.

  • InstallationComplete

    Thanks for the tutorial… I’ve made it to the php script part and am getting some errors… please see the screen cap.

    http://screencast.com/t/YQl2AVq6

    Thanks!
    Ic

    • Hi Ic,

      I never get that errors. I have tried couple of scenarios, but I couldn’t reproduce those exact errors. I assume those errors are pointing to the script file?

      The page on the screenshot is supposed to be filled automatically with the database info. It appears from the errors that it can’t fetch the database info.

      Try to manually enter the database info. For example, if you use the info on above tutorial, it will be:
      – Server Name: localhost
      – Database Name: exampledb
      – Username: exampledb
      – Password leave blank
      – Charset: utf8
      You can change the info using your own database info.

      Hope that helps.

  • Jessica

    Thank you for the great tutorial! I’ve followed the tutoral exactly, yet when I view my site I get “Page not found” (though it appears the correct theme is loading), and all navigation links still link to the live site’s URL. Any idea where I may have gone wrong?

    One more question – in the wp_blogs databae table I have three URLs (one for each sub-site) – should I change all of these?

    Thank you!

  • donglelord

    Is there anything I should be mindful of when doing this with an HTTPS site?

  • Erin Fraser

    Thank you! This is the first tutorial that actually made sense and worked!

    My multisite installation is just about 100%, but I’ve noticed one little thing I’m hoping you can help me with.
    There are a couple relative image paths in my site (done by another dev) and rather than referencing the WP installation folder, they reference the base XAMPP installation localhost. So those links don’t work because they’re going back a level too far in the folder structure. Using the structure in your example, my site structure would be:

    localhost/example/ci-ic (where ci-ic is one of the sites in the multisite, example, is the base network site)

    When I have some images that references: /ci-ic/wp-content/uploads/sites/2/2016/09/myimg.jpg
    the link is broken, but this works: /example/ci-ic/wp-content/uploads/sites/2/2016/09/myimg.jpg

    So my question is, why the relative path not relative to the /example/ folder? Why is it relative localhost?

    I’m assuming this is because there’s a configuration somewhere that is incorrect but I don’t knwo which one.
    Can you help?

    • Hi, Erin. Thank you for finding my tutorial useful.

      That problem with relative paths on XAMPP is because XAMPP use /localhost as the root – rather than use your site’s root (/example).

      Are those relative paths located on template files? If so, I suggest to use dynamic codes instead of relative paths. For example: < ?php echo home_url(); ?>/ci-ic/wp-content/uploads/sites/2/2016/09/myimg.jpg.

      Or, alternatively, if you must use relative paths, you can follow this temporary solution on Stackoverflow here: XAMPP relative urls not working correctly.

      Hope that can help.

  • Ed Fong

    Followed your tutorial and got it to connect but not all aspects of website work. Have slider revolution plug in and that’s working. I am also not able to access admin page.

    • Is there any specific error or can you describe what happened when you access admin page? Do you use HTTPS on admin pages on live site?

      I never use slider revolution plugin. Can you check if there is specific settings that still point to the live site’s url? Or is there some kind of purchased activation code that restrict the slider to be used only on one site / on live site?

  • ugo

    Thank you Dhyayi!

    This is great and well explained. Simple an to the point.
    The local wpmu site works perfectly after following your procedure!

    For the beginners like me, I’d like to underline that the
    RewriteBase /example/
    need to be done for every RewriteBase instance in the .haccess!

    Also, about some of the wp-admin problems mentioned in the comments:
    At the end, I had to restart the localhost and the browser to solve a small issue
    (when I tried to access http://localhost/example/wp-admin
    the browser was redirected to: http://localhost/wp-admin/ )
    All went away after reinitialization

Leave a Reply

Your email address will not be published. Required fields are marked *