Moving WordPress Multisite from Live Server to Localhost Safely (2021)

Written by
(Last Modified: 28 July 2021)
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.

[Last major update on 27 June 2021. In this version, I use the latest version of interconnectit's Search Replace DB script (v4.1.2). Along with that change, I also streamlined this tutorial and thus made it has fewer steps than the previous version. As a result, some comments are outdated as they pointed to certain step number in the past. If you are confused or need any help, please don't hesitate to leave new comment below or contact me.]

The Case

In this tutorial, I will explain how to move WordPress Multisite from live server to localhost with an example case:

  • We will move WordPress Multisite from http://example.com to http://localhost/example.
  • The live server is using cPanel and the localhost is running on XAMPP.

How to Migrate WordPress Multisite from Live Server to Localhost:

Step 1 - Download the 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.

Step 2 - Download the database from live server

Go to cPanel's phpMyAdmin. Export the entire database of WordPress Multisite that we want to move.

Step 3 - Extract the downloaded WordPress files to localhost

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' (\xampp\htdocs\example).

NOTE:
If you installed cache or security plugins on your live site, you may have to deactivate it on the localhost by renaming the folder's name to something else temporarily. For example, if you installed W3 Total Cache plugin, go to the plugin's folder (\xampp\htdocs\example\wp-content\plugins\w3-total-cache) and rename it to something else e.g. 'Xw3-total-cache'.

Step 4 - Create new database in the local phpMyAdmin

Visit http://localhost/phpmyadmin/. For this tutorial, I will name it 'exampledb'. Import the database that we have exported from live site in Step 2.

Step 5 - Edit the .htaccess

Open .htaccess in the root folder (\xampp\htdocs\example\). Edit RewriteBase into:
RewriteBase /example/

NOTE:
If there are redirect issues or you can't access your site on localhost at all, there might be additional codes added to .htaccess by your installed cache or security plugins. If that's the case, comment or remove those codes. Retain only the codes in between #BEGIN WordPress and #END WordPress.

Step 6 - Edit the wp-config.php

Open wp-config.php in the root folder. 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/');

NOTE:
If your live site uses https, comment or remove any lines related to the https settings on the local site, for example: define('FORCE_SSL_ADMIN', true);

Step 7 - Prepare to change all urls (download the Search Replace DB script)

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 the latest Search Replace DB script from interconnectit's GitHub page. For this tutorial, I use Search Replace DB v4.1.2.

Step 8 - Extract the Search Replace DB script to root

Extract the whole folder to root. It will be \xampp\htdocs\example\Search-Replace-DB-4.1.2. This script is quite powerful and can be used to break your site. So, please remember to remove it once you finish using it.

Step 9 - Run the Search Replace DB script

Run the script by visiting http://localhost/example/Search-Replace-DB-4.1.2.

You will see that there are 5 main sections in this page, i.e. SearchReplace, Database Details, Which Tables?, Let's go, and DELETE.


The following steps (Step 10 - Step 14) will be about those sections in the script's page (http://localhost/example/Search-Replace-DB-4.1.2).

Step 10 - Input urls in the 'SearchReplace' section

Input 'http://example.com' in 'replace' field and 'http://localhost/example' in 'with' field.

NOTE:
If your live site also has https urls, you can click the '+ add more search terms' and input 'https://example.com' in the additional 'replace' field.

Step 11 - Add the database information in the 'Database Details' section

You only need to fill the database name and username. Input 'exampledb' in the 'database name' field and 'root' in the 'username' field. Click the 'Test connection' to make sure the script can connect to the database. If there is no issue, a green message of 'Success, You are connected' will show up.

Step 12 - Change the settings in the 'Which Tables?' section

Select 'all tables'. Input 'guid' in the 'columns to exclude (optional, comma separated)' field.

Step 13 - Search and replace urls

Go to the script's 'Let's go' section. Click 'Do a safe test run' to see if there would be any issues. If there are no issues that need your attention, you can proceed to click 'Search and Replace' button.

Step 14 - Delete the script

Now you can remove the Search Replace DB script from your root folder. You can click the 'delete me' button on the 'DELETE' section on the script's page. However, it will still leave the folder and some files. I prefer to remove it directly from \xampp\htdocs\example.


Step 15 - Change domain and path in wp_site table

Go to the 'exampledb' database (navigate from http://localhost/phpmyadmin/).

Then, click the wp_site table (or yourtableprefix_site). Change domain, from 'example.com' to 'localhost'. And path, from '/' to '/example/'.

Step 16 - Change domain and path in wp_blogs table

As in Step 15, you also have to change all of the domains and paths in wp_blogs table (or yourtableprefix_blogs).

Change domain, from 'example.com' to 'localhost'.

Change path from '/' to '/example/'. If you have second site named as '/site2/, you have to change the path to '/example/site2/'. Do the similar to all paths.

Step 17 - Final check

Try to visit the site in http://localhost/example and login to admin area from http://localhost/example/wp-login.php.

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.


FAQ

Can I use this tutorial to move WordPress multisite from localhost to live server?

Yes, you absolutely can. In fact, you can also follow the steps in this tutorial to migrate WordPress single site from localhost to live server or from live server to localhost too! I can say that because I also use this tutorial for those purposes 🙂

However, of course, there are things that you have to adjust for those situations. The main things you have to note are the database information and the urls or paths in your live server and localhost. Basically, you only need to switch those details between live server and localhost.

If you want to migrate WordPress single site, you can follow this tutorial step by step, but skip Step 15 and Step 16 as those two steps are exclusively for WordPress multisite.

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

54 Comments

Add new comment
  • i have done it countless number of times. it says error database connection

    • Hi. I’m sorry to hear that.

      You can try the following:

      • Make sure the database is not corrupted. You can try to download the live database again, just in case.
      • Make sure you have entered the correct database information and edited the two lines for Multisite setting in your wp-config.php (step 6 in tutorial above)
      • Try to use the latest interconnectit’s Search and Replace Database script. It’s currently v4.1.2. Download the script from interconnectit’s github page. Extract the whole folder to your root and access the folder by visiting ‘http://localhost/example/Search-Replace-DB-4.1.2/’. Input the urls you want to search and replace, database name, username, and don’t forget to input ‘guid’ in ‘columns to exclude’. Side note: As soon as I have free time, I will update the tutorial above with more detailed step by step to use the latest interconnectit script
      • Make sure you do step 17 and 18

      Let me know if those solutions fix your issue or not.

  • Sile

    I really appreciate what I learned here, and it worked for me at second trial cause I wasn’t following the search and replace process well. Thank you very much.

  • Dhyayi has anyone asked you about the other way around? How to move a multisite from a localhost to a server?

    • I used it to move multisite both way (live server to localhost and localhost to live server). You just need to change the related information, especially the ones from step 5 until the last step.

  • Thanks a lot! The method still works in 2019.

  • great tutorial! thanks a lot!!!

  • 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

  • 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?

  • 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: /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.

  • donglelord

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

  • 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!

  • 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.

  • 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.

  • 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!)

      😀

  • 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!

  • 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

  • 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
    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.

  • 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.

  • Anonymous

    Very nice. Clear instructions.

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

    Cheers!

  • 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?

  • Sorry, its worked after google registration 🙂

  • 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?

  • 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. 😀

Leave a Reply

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