admin管理员组

文章数量:1122832

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!

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!

Share Improve this question edited Mar 4, 2016 at 9:27 Sven 3,6641 gold badge34 silver badges48 bronze badges asked Mar 4, 2016 at 5:06 stormchaserstormchaser 431 silver badge4 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 3

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>
.
.
.

本文标签: WordPress multisite with domain mapping and virtual host on local with fake domain