Simplifying the original question, so this answer is to my original, more specific question about Apache setup.
Do Apache variable DOCUMENT_ROOT and PHP variable doc_root need to match exactly?
In my local development setup under MAMP for Windows, in file httpd.conf I set DocumentRoot as
DocumentRoot "C:/MAMP/htdocs"
whereas in httpd-vhosts.conf I set
DocumentRoot "C:/MAMP/htdocs/my-dev-install"
This seems to work ok with one site, but how do I get multiple sites working on localhost without having to switch on and off each Virtual Host to pivot between sites?
I’ll update this answer as I find pieces.
First, DocumentRoot
definitions in httpd-vhosts.conf will override the default defined in httpd.conf,
which responds to any requests that aren’t handled by a definition. These values also provide defaults for any containers you may define later in the file.
–(comment from httpd.conf)
My hosts
file:
127.0.0.1 example.d1
::1 example.d1
127.0.0.1 example.d2
::1 example.d2
My httpd-vhosts.conf
:
NameVirtualHost *:80
# ======= New - theme 1 =======
<VirtualHost *:80>
DocumentRoot "C:/MAMP/htdocs/my-dev-install-1"
ServerName example.d1
ServerAlias example.d1
# these 4 lines enable error logs ====modify the log names to make it clear which dev site the errors belong to
RewriteLogLevel 3
RewriteLog "C:/MAMP/logs/rewrite.log"
ErrorLog "C:/MAMP/logs/d1-error_log"
CustomLog "C:/MAMP/logs/d1-access_log" common
</VirtualHost>
# ======= New - theme 2 =======
<VirtualHost *:80>
DocumentRoot "C:/MAMP/htdocs/another-dev-install-2"
ServerName example.d2
ServerAlias example.d2
# these 4 lines enable error logs
RewriteLogLevel 3
RewriteLog "C:/MAMP/logs/rewrite.log"
ErrorLog "C:/MAMP/logs/d2-error_log"
CustomLog "C:/MAMP/logs/d2-access_log" common
</VirtualHost>
The .htaccess
files have only standard WordPress language (no difference between the two).
Partial success — when I visit http://example.d1
or http://example.d2
, Apache sends me to the correct sites’ home pages. However, clicking on links within .d2 take me back to localhost
, which somehow is defined as the first site (example.d1
).
Could be a 302 in my browser perhaps. Or, maybe I need to play with the NameVirtualHost *
statement.