3

I have searched all over and have found many tutorials on how to set up a multisite, domain mapping, and even use virtual hosts on my local machine, but I can't seem to find how to do all of those.

I would like to have WordPress multisite run on my localhost using fake domain names, such as mysite-1.dev, mysite-2.dev, mysite-3.dev, etc.

I'm running XAMPP with Apache on a Windows machine. In the httpd-vhosts file, I must specify a folder for the fake domain to go to, but if I'm using WordPress multisite, I'm unsure how to that.

Here is part of my httpd-vhost file:

<VirtualHost *:80>
    DocumentRoot "C:/home/mysite-1"
    ServerName mysite-1.dev
    Alias /mysite-1.dev "/home/mysite-1"
<Directory "/home/mysite-1">
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "C:/home/mysite-2"
    ServerName mysite-2.dev
    Alias /mysite-2.dev "/home/mysite-2"
<Directory "/home/mysite-2">
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "C:/home/mysite-3"
    ServerName mysite-3.dev
    Alias /mysite-3.dev "/home/mysite-3"
<Directory "/home/mysite-3">
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>
</VirtualHost>

In my hosts file, I have:

127.0.0.1   mysite-1.dev
127.0.0.1   mysite-2.dev
127.0.0.1   mysite-3.dev

I've set up multisite in WordPress, and entered the wp-config.php and .htaccess files as required.

wp-config.php file is as follows:

define('WP_ALLOW_MULTISITE', true);
define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', true);
define('DOMAIN_CURRENT_SITE', 'mysite-1.dev');
define('PATH_CURRENT_SITE', '/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);
define( 'SUNRISE', 'on' );
define('WP_TEMP_DIR',ABSPATH.'wp-content/uploads/');

And .htaccess is as follows:

# BEGIN WordPress
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]
# END WordPress

By doing the setup this way, when I go to mysite-2.dev and mysite-3.dev, it looks in the folder, and there is nothing in c:/home/mysite-2.dev and c:/home/mysite-3.dev, so it shows an error:

Call to undefined function wp_get_current_user().

In c:/home/mysite-1.dev, it has all of the WordPress multisite files, plugins, themes, etc., so it works fine.

I know this is probably a configuration issue, but I am unsure how to set it up properly. Can anyone point me in the right direction for setting a WordPress multisite using fake domains and domain mapping?

Thank you all in advance!

1

DocumentRoot for each VirtualHost should point to the directory where you installed WP multisite. There is no actual directory for subsites, they're all virtual.

Using your example:

<VirtualHost *:80>
    DocumentRoot "C:/home/wp-intall-directory"
    ServerName mysite-1.dev
    # not required Alias /mysite-1.dev "/home/mysite-1"
    <Directory "/home/wp-intall-directory">
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "C:/home/wp-intall-directory"
    ServerName mysite-2.dev
    # not required Alias /mysite-2.dev "/home/mysite-2"
    <Directory "/home/wp-intall-directory">
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>
.
.
.
  • Works like a charm! Thank you. This is the first explanation that I've found. Makes sense because it is "virtual" host, so there is no folder. :) – stormchaser Mar 4 '16 at 11:33
  • A virtual host can have it's own DocumentRoot but not in the case of WordPress multisite. – BillK Mar 4 '16 at 18:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.