WordPress Multisite Problems with Vagrant

I had some problems setting up Multisite on WP with the Vagrant environment.

The big issue is that the the domains and URLs need to be set just right. This is a little more complicated than a typical server setup because dev setups usually take shortcuts on DNS.

You need to fix the domain names in all the locations where they’re resolved.

First, set up DNS. Set up domain names for all the domains you’re going to develop, but use local names like “foobar.lo” instead of “foobar.com”. They can all point to the IP address your dev server exposes via Vagrant, usually 192.168.33.10.

Second, check /etc/hosts on the host and make sure you don’t resolve any of those domains.

Third, “vagrant ssh” into the dev VM, and check that /etc/hosts doesn’t contain any entries that will resolve 127.0.0.1 to something like machinename.local. Such a line may have been added at some point to aid in development. WP may pick up this name (going from IP address to machine name), and use it.

Fourth, on the dev VM, open up mysql and look at the first two entries in the wp_options table. These should be 1, siteurl, and 2, home. Set them both to the URL with the IP address of the dev server, like “http://192.168.33.10”. This may fix the problem.

Fifth, check the wp-config.php and .htaccess files. Make sure in wp-config.php, DOMAIN_CURRENT_SITE is defined to the IP address of the dev server.

When your done, all these settings should point to the same domain. The login and admin pages all do some writing of URLs, and forwarding to different URLs, and they all need to match. If they don’t match, the cookies will be set on the wrong domain, and you won’t have access to the admin pages.