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.
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!
Normal Wordpress migration:
- Backup your database from localhost.
- Create new database on new server, import the exported database here.
- Upload all Wordpress-files to the server.
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.
- Visit http://mysitename.com/wp-admin, login and go to permalinks settings and press save to generate a new .htaccess.
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.
How to migrate multisite:
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:
- Export database, same as above.
- Upload new database, same as above.
- Add all your Wordpress files, same as above.
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!
You can follow the tutorial at this link.Its explained very nicely and is very easy to understand.
PS for step 6 i suggest you use Velvet Blues WordPress plugin