I'm trying to run a Wordpress MultiSite config locally using MAMP.
I copied the database and php files.
Then I change the main domain to localhost:8888
and turned off subdomains:
define('DOMAIN_CURRENT_SITE', 'localhost:8888');
define('SUBDOMAIN_INSTALL', false);
I kept getting an error "Cannot connect to database".
When I went to localhost:8888/wp-admin I got a more detailed error, that my domain couldn't be find in new2_wp_blogs
. So I went into the database and switched all the sites' domains to localhost:8888
and the paths to the previous subdomains.
I also went into wp_options
and changed siteurl
and home
to http://localhost:8888
Now when I go to localhost:8888
the primary site works.
When I go to my first subsite site, I get redirected to localhost/<nameofsite>
When I go to localhost:8888/wp-admin
I get redirected to:
http://localhost:8888/%3Cbr%20/%3E%3Cb%3ENotice%3C/b%3E:%20%20Use%20of%20undefined%20constant%20PWP_NAME%20-%20assumed%20'PWP_NAME'%20in%20%3Cb%3E/Users/anatoliyzaslavskiy/Sites/even-wp/wp-content/mu-plugins/mu-plugin.php%3C/b%3E%20on%20line%20%3Cb%3E101%3C/b%3E%3Cbr%20/%3Ehttp://localhost:8888/wp-login.php?wpe-login=PWP_NAME
A easy workaround is creating entries in your hosts file (for windows: %SystemRoot%\System32\drivers\etc\hosts
, for linux: /etc/hosts
). For that, you choose a domain name which is not using a real top level domain, e.g. wordpress.local and add a list of multisite examples in your hosts file:
127.0.0.1 wordpress.local
127.0.0.1 www.wordpress.local
127.0.0.1 test.wordpress.local
127.0.0.1 example.wordpress.local
127.0.0.1 more.wordpress.local
Now you can use wordpress.local
for your multisite domain. Of course you need to configure your apache to handle these hosts.
If you already have a live website and just want to create a sandbox version on localhost, then instead of manually migrating the site you can use plugins like duplicator which takes care of all the migration issues and gives you a nice installer to use.
While duplicator doesn't support multi site yet but here is another plugin that has support for multisite https://wordpress.org/plugins/ns-cloner-site-copier/