I am trying to move a deployed WordPress Multi-Site to a local environment. I backed up the server database and files. In my local environment, I created a new database and imported the backup. I also copied the server files to my local machine.
I did these steps:
I changed wp-config.php and updated it with the new db-name
, db-username
, db-password
and set define('DOMAIN_CURRENT_SITE', 'www.mysitename.com');
to define('DOMAIN_CURRENT_SITE', 'localhost/mysitename');
.
I changed option_value
in the wp-option database table to point to my local address.
I also deleted these lines from .htaccess:
# Redirect non-www urls to www
RewriteCond %{HTTP_HOST} !^www\.mysitename\.com
RewriteRule (.*) http://www.mysitename.com/$1 [R=301,L]
But when I go to 127.0.0.1/mysitename I get this error: This webpage has a redirect loop.
And when I change define('DOMAIN_CURRENT_SITE', 'localhost/mysitename');
to define('DOMAIN_CURRENT_SITE', 'localhost');
and I go to 127.0.0.1/mysitename address it shows me the phpinfo() page.
How can I fix my problem?
Please explain if I must set something in .htaccess and wp-config.php files.
Thank you so much.
Install the All-in-one WP Migration plugin from the WordPress.org plugin directory. Click on the Upload Plugin button at the top of the screen and click browse to select the Multisite Extension's . zip file from your local files.
WordPress multisite is a core WordPress feature that allows you to easily create multiple sites using the same WordPress installation. The best part is that you can use different domains for each of your websites.
Method 1. Transfer WordPress from Local Server to Live Site Using a Migration Plugin This method is easier and recommended for beginners. We’ll be using a WordPress migration plugin to move WordPress from localhost to a live site. Step 1. Install and Setup the Duplicator Plugin
Install the plugin on your local site and export your site’s files. Next, install the plugin on your new WordPress site on your live server and import the same files. After you’re done, make sure you backup your WordPress site so that you always have a safety net to fall back on when things go wrong. What Next?
If you will not use a custom domain on the Multisite and the migrated single site no longer needs its own hosting, delete the WordPress site and cancel your domain and hosting account. If you will use a custom domain on the Multisite, then you only need to delete the WordPress site and cancel the hosting account.
Import your WordPress files and database to local server After downloading your WordPress files, you need to create a folder on your local server where you want to import the local site. If you are using WAMP then you would want to create a folder inside C:\wamp\www\ folder for your local site.
Edit: Recently had to migrate a multi-site once again, and this guide still works fine as of 01/03-2016. The database edits are very figgedy, one mistake and you either get white screen of death or error connecting to database, so pay attention :)
I couldn't figure out of to allow localhost links with protocol (http://) so if you see "(http:)localhost" read it as http:// localhost/. If someone could edit this for me that would be great!
Edit wp-config.php, changed database name, username and password. Usually below "define('WP_DEBUG'.. I define "WP_HOME" and "WP_SITEURL", these will override Wordpress database settings for path to root. "DOMAIN_CURRENT_SITE" is used for multisite installations. So if it isn't a multisite, don't use this, if it is a multisite, just use this and not WP_HOME and WP_SITEURL.
define('WP_HOME', 'http://mysitename.com');
define('WP_SITEURL', 'http://mysitename.com');
If you uploaded .htaccess from localhost aswell, delete it from the server.
And you're done! No need to bother doing database changes. For your localhost installation, just define WP_HOME and WP_SITEURL to localhost instead.
Multisites in Wordpress is a pain in the ass to migrate, it involves several database changes and even when you made everything correct it seems to only work some of the times without errors. However these are the recommended steps:
Edit your wp-config.php with the new database info, add the following defines:
define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', false); // true or false depending if the paths for each multisite is pointed by a subdomain.
define('DOMAIN_CURRENT_SITE', 'localhost'); // localhost is the DOMAIN of the new location, so even if the ABS_PATH is localhost/whatever, you should have localhost here.
define('PATH_CURRENT_SITE', '/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);
You should have all of these in the wp-config.php of the site you are trying to export, so just copy-paste them from there, and edit DOMAIN_CURRENT_SITE.
Edit your htaccess like this (Rewritebase /path/ should be relative path, ie if your website is located at localhost/mypage it should be "RewriteBase /mypage/"):
# MultiSite
RewriteEngine On
RewriteBase /subfolder-from-localhost/
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]
Database edit time! These steps needs to be done for every subsite your multisite has, if I type change table "wp_site", you should replicate it in wp_site1/wp_site2 etc...
In table wp_options: change fields "site_url" and "home" to (http:)localhost/subfolder (no trailing slash).
In table wp_blogs: change "domain" to "localhost", and "path" for every entry for each subsite to /subfolder/ (must have trailing slash)
In table wp_site: change "domain" to "localhost", and "path" to /subfolder/ (must have trailing slash)
In table wp_sitemeta: change "siteurl" to full path ie (http:)localhost/subfolder/ (must have trailing slash)
Now you should atleast have access to your page, if you still get redirection loop or white screen of death, double check the database changes. Now login to admin, and we need to change some hardcoded URLs in the database, I usually do this with a plugin called "Seach and replace", so download and install this plugin, and use it by typing in what it should search for (old url) and what to replace it with (new url).
Search for: http://mysitename.com
Replace with: (http:)localhost
Now hopefully you have a functional migration of the multisite. As I noted I've done this a couple of times, and it almost seems random if everything works or not. I'd say I had success with this approach perhaps 6 out of 8 times.
Edit: Added how to migrate multisite.
This is close but a little different for a multisite that uses subdomains. You are required to edit your host file to show each site url as localhost(LINK):
C:\Windows\System32\drivers\etc
127.0.0.1 localhost
::1 localhost
127.0.0.1 localhost.com
127.0.0.1 subdom1.localhost.com
127.0.0.1 subdom2.localhost.com
etc..
Then, editing the database as stated above worked, ignoring any subdirectory changes beyond the .htaccess mentioned above but leaving the Base as /
# MultiSite
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
In my install, I needed to update some across the headers and footers to get the styles to load.
Thanks to @ninja for pointing me in the right direction!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With