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!
Ninja's answer helped a lot. Though you can shorten the amount of the steps described in his answer by using wp-cli for database replacements, so you don't need any third party plugins and to edit single database cells manually. wp-cli's search-replace function works amazingly perfect, at least in my experience in case of usual wp sites. But in combination with the steps in ninja's answer it also has worked with multisite in my case. Here is a great description on how to install wp-cli: https://wp-cli.org
To replace a string through out all the sites run:
wp search-replace //oldurl.com //dev.url.test --network
Yes, the url strings are not wrapped with quotes. From my experience this way the replacement works perfect without any issues which might appear using quotes.
To replace strings in a particular site:
wp search-replace //oldurl.com //dev.url.test --url=https://oldurl.com
To see what urls are mapped to the sites:
wp site list --network
Though the db replacements worked well. I had to deactivate multisite in the wp-config.php (by removing all the multisite constant definitions) and all the plugins first and then to reactivate them from network dashboard.
wp-cli search-replace docs:
https://developer.wordpress.org/cli/commands/search-replace/
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
Related
(Sorry for the long post as I'm baffled by many aspects of this issue)
I recently converted my WordPress single-site installation to a multisite network. The former site is now the main site of my network. I'm trying to create multiple subsites for my network but I'm running into unusual issues with the URL.
I have the network setup as a subdomain network. I plan to initially create the subsites as
http://subsite1.maindomain.com
http://subsite2.maindomain.com
But then later map these to
http://www.subsite1.com
http://www.subsite2.com
I'm nowhere close to the domain mapping because even the subdomains are not working properly.
The first issue I encounter upon creating a new subsite...After entering all of the details such as site URL, title, and admin email, I am then presented with a blank white page with no error message. I'm not being redirected to the subsite's dashboard or back to a network page. In order to navigate back, I have to enter my network admin URL directly in my browser in order see the new subsite among my list of sites.
The second issue I encounter is though I set the site URL as "http://subsite1.maindomain.com", when I'm viewing any of my subsites and hover over the Dashboard or Visit link, the URL shows that of my main site, http://www.maindomain.com and not of my subsite. I am able to Edit the subsite and change the basic details but I can't get into the dashboard.
It's important to note that the URLs were working for a brief period of time with subsites that I have since deleted. I would create a new subsite and I would be able to get into the dashboard. But suddenly, with no rhyme or reason, the links started linking to the parent and I lost access to the subsites' dashboards. So then I deleted those subsites using the admin network interface and tried creating new ones but I was never again successful.
I've noticed that with the subsites that I created long ago, WordPress created new database tables for them starting with wp_X (where X was the id of the subsite). Now when I inspect my database, I see no tables that represent any subsites. Perhaps those were tables created by plugins because, as I stated, I was once able to get into my subsites and turn plugins on and off.
Also when I was creating those subsites previously, after adding one I would immediately see the subsite listed under the My Sites dropdown. They no longer appear there.
When I go to edit my subsite, even though I originally entered the URL "http://subsite1.maindomain.com", the URL shows as "://subsite.maindomain.com".This doesn't seem right. And when I try to click "Upgrade Network", I am presented with an issue saying one of the subsite URLs is invalid. I believe this is because of the "://" at the beginning of the URL. I've tried removing this from the URL and resaving it, but it always saves with it.
Everything in my database looks fine.
wp_blogs looks like
blog_id
site_id
domain
path
1
1
www.maindomain.com
/
15
1
subsite1.maindomain.com
/
no data in blogs_meta
wp_site has only one record
id
domain
path
1
www.maindomain.com
/
wp_sitemeta contains a few thousand records but the site_id column for all of them is 1. The value for siteurl is https://www.maindomain.com/
wp_config.php
define( 'WP_ALLOW_MULTISITE', true );
define( 'MULTISITE', true );
define( 'SUBDOMAIN_INSTALL', true);
define( 'DOMAIN_CURRENT_SITE', 'www.maindomain.com' );
define( 'PATH_CURRENT_SITE', '/' );
define( 'SITE_ID_CURRENT_SITE', 1 );
define( 'BLOG_ID_CURRENT_SITE', 1 );
.htaccess
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ $1 [L]
RewriteRule . index.php [L]
I thought maybe the issue could be with SSL or DNS, but the URLs should still link and display the correct link when I hover over the Visit or Dashboard links.
I've deactivated most of my plugins network-wide and really don't want to deactivate any more plugins or my main theme as it will cause my main site to be down until they are activated on the site level. In my experience, reactivating my theme once I deactivated doesn't always honor my previous settings. I don't think the issue is a plugin or theme conflict.
I'm trying to build a Magento (1.9.3.1) staging site in a subdomain but can't get it to work properly. The site is working but no images, js or css files are being loaded. I've searched around but all the answers I've found don't work for me.
My main website structure is www.domain.com which has it's own website (not Magento) but then I have subdomain.domain.com with Magento installed.
Following another answer I tried editing .htaccess and added the following:
RewriteCond %{HTTP_HOST} ^subdomain\.domain.com$
RewriteRule ^/(.*) http://subdomain.domain.com/index.php [L]
but that didn't work. I tried different variations of that too.
Any ideas what I'm doing wrong? I have a dedicated server and the domain structure is:
/httpdocs
/subdomain.domain.com
where the main website root is in httpdocs. Could that be the issue?
The subdomain is set correctly in the core_config_data table as well.
Most packages like magento require root access.. this may be the issue.
Also, try to check the path to youre images.
Okay #Olcan set me in the right direction so thanks. It wasn't actually root access needed but directory permissions were not set correctly.
All the directory permissions were set to 750. Changed them to 755 and everything works. Didn't need to do anything with .htaccess either so I left it at the default
RewriteRule .* index.php [L]
and it works.
I am new in creating a website using wordpress. I am using xampp to create a local wordpress website and my website run under: localhost/mysite. I want to import my local website to my live website https://vsaftest.wordpress.com/ by going to the setting of my local website and then changed the wordpress Address and site address from http://localhost/mysite to https://vsaftest.wordpress.com/. After that then I can not access to my local site using http://localhost/mysite anymore, and inside the website https://vsaftest.wordpress.com/ there is nothing there also. I know that I made a mistake here but then anyone can help me how can I change back so that I can access my site from localhost :(
I've never used Wordpress before, but going purely from your desription, you seem to think that changing a setting on and for your local machine will somehow affect the settings on a remote machine.
and inside the website https://vsaftest.wordpress.com/ there is nothing there also
But was there nothing there beforehand either? In other words; Nothing's changed?
I think the reason you cannot view your local site anymore is precisely because you made the change you said you did. Instead of its changing the remote machine (which it probably doesn't do...I don't do WP dev, so I don't know for sure) it changed your local machine.
Can you not just change wordpress Address and site address on your local site back to what it was before?
There are many pitfalls one might encounter when moving a Wordpress website from a local development environment to production. Here are the main things to remember and look out for.
Htaccess
When developing in Xampp it's very common to include the website's directory name in the .htaccess' RewriteBase and RewriteRule. Assuming your production website will be situated in the root directory you'll want to remove the directory references from your .htaccess file.
For example your development .htaccess file might look like this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /mysite.com/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /mysite.com/index.php [L]
</IfModule>
# END WordPress
But in production you'll need to adjust it to look like this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
One good development practice you can adopt is creating .live and .dev htaccess files. Create .htaccess.dev and .htaccess.live files and store your development and production htaccess data in them respectively. Your real .htaccess file will then contain the current active data and you can easily copy/paste from the .dev and .live files to it if needed.
Database
When you move a Wordpress website to production you must also create a production database for it. Make sure the database created has the same collation as the development one and that the database credentials in your wp-config.php file are updated to reflect the production database user, password, etc. Remember that if your WP_DEBUG variable is not set to true database errors will not be shown if a database connection error occurred in your production website. Because of that database errors in production more often than not lead to a "white screen of death".
Another thing one must make sure (and you already mentioned in your question) is that the siteurl and homeurl keys in your wp_options table are updated to reflect the production website url. In case multiple domains exist (for example .com and .co) one can enforce the correct url by defining the WP_SITEURL and WP_HOMEURL constants dynamically within the wp-config.php file.
PHP version
Last but not least, make sure the PHP version required for your website is compatible with the production server's PHP version. 2017 is a transitional year in terms of PHP support. Whereas Xampp already supports PHP 7 sadly many servers still do not.
I recently changed my wordpress blog's server and URL. Before, it was located at subdomain.website.com and now it is located at website.com/newurl. I copied over the files and database, and updated the site URL and and website URL successfully. Initially, the site seemed to have been functioning properly. Somewhere along the road, the server started feeding back an infinite redirect loop on blog posts only. I can properly view the blog's homepage, but when I try to access specific blog posts it enters into an infinite redirect loop. If I turn of permalinks, and use the raw url i.e. website.com/newurl/?p=232 it serves the page properly.
Any idea why my permalinks no longer work? I already tried turning off plugins, and it still doesn't work. I also tried resetting the htaccess file with no success. Any advice is much appreciated.
Here is my htaccess file:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPress
Also, I am not sure it is relevant or not, but the wordpress installation is in a subdirectory of a magento installation.
A few things to check...
Have you updated the table wp_options? - There are two fields in there that need to be updated when migrating a website, the option names are siteurl and home.
Also depending on your server settings, you may have to manually update your .htaccess as updating your permalinks doesnt always update your htaccess, a problem Iv run into before.
One last idea, the ‘AllowOverride FileInfo’ directive may be the problem, the .htaccess needs to override the main httpd.conf configuration file and is unable to do so without this directive. (This fixed a problem I had a while ago when the postname permalinks ect were not working but using the actual URL was)
Goto Settings -> Permalink -> Select (Post name) and Save it. No matter it is already selected just do it once again. Goto your site and Refresh page and check urls again. This is a common issue occurs when you migrate in other ways.
Please don't touch your htaccess file.
I have experienced this kind of stuffs in the past and only shows right after you moved wordpress to either another folder, a new domain, or when you change hosting.
To fix it, please correct your Wordpress Address and Site Address... I usually just addd/remove WWW and/or changes HTTPS to HTTP and vice versa
In the end the problem was a plugin titled "WP No Category Base" that was causing the redirect loop. Once I disabled it my website was functioning properly again.
Next time you want to move a WordPress site, you can consider using a WordPress plugin to handle the job for you.
There is several plugins that can do this for you.
Check this one : Golive
GoLive Features:
Automatically Export the Database from Source Server
Transfering the files via FTP automatically
Auto-import Database in Remote/destination server.
Update .Htaccess properly
Update wp-config.php file on destination server with the new credentials.
Replace the URLs in Database (Posts, Pages, Menus…), and keep auto-update serialized objects too.
I just pulled a copy from a live site and installed locally using XAMPP. The directory is:
127.0.0.1/website-files/websitename
The homepage pulls up just fine, but no images load. The links do not work either. Image and link URLs have not updated to reflect the new directory. They still show as:
/categoryname/pagename
Instead of
/website-files/websitename/categoryname/pagename
The site is wordpress, and the general settings are updated:
Wordpress Address http://127.0.0.1/website-files/websitename
Site Address http://127.0.0.1/website-files/websitename
I added this to functions.php, which I assumed would do all the changes I needed:
update_option('siteurl','http://127.0.0.1/website-files/websitename');
update_option('home','http://127.0.0.1/website-files/websitename');
.htaccess looks like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /website-files/websitename/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /website-files/websitename/index.php [L]
</IfModule>
I run into an issue every time I move a website to a new dev server, but this one is a first. What am I missing here?
Avoid using a leading / for any links for your website, so instead of:
foo
<img src="/images/bar.jpg">
Do this:
foo
<img src="images/bar.jpg">
And finally, you might want to experiment with adding a "base href" tag to the top of your HTML, which would have a different value depending on what server you're running on. A quick google for base href will teach you how this works.
You might have to restructure how you build webpages to make this happen. That's simply how things are if you want to be able to run a single website on more than one server.
If you're using Wordpress or another similar open source framework, you might be screwed. Some of them are simply incapable of operating on more than one server.
Try to confirm that home and siteurl have been updated in your local database's wp_options table.
Alternately you can can try setting WP_HOME and WP_SITEURL to point to your local files in wp-config.php. This overrides the settings in the options table.
define('WP_HOME', 'http://127.0.0.1/website-files/websitename');
define('WP_SITEURL', 'http://127.0.0.1/website-files/websitename');