I’ve recently tried out a new way define my virtual hosts on my development machine. I’ve always had a configuration file in my home dir (that gets included from httpd.conf) that looks something like this:
NameVirtualHost *:80
ServerName drupal.local
DocumentRoot /Users/hugowett/Sites/drupal/public_html
AllowOverride All
Order deny,allow
Allow from all
<VirtualHost *:80>
ServerName somesite.local
DocumentRoot /Users/hugowett/Sites/somesite/public_html
<Directory /Users/hugowett/Sites/somesite/public_html >
AllowOverride All
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
Each time I started a new project I would create the project directory, add a new VirtualHost entry and add the domain to my /etc/hosts-file. Then I just needed to restart apache and everything worked.
Now I’ve defined a dynamic virtual host instead. This way I just need to create a project directory according to the /Users/hugowett/Projects/{$domain_name}/public_html pattern and add the domain to my hosts file. No Apache configuration changes or restarts required.
# get the server name from the Host: header
UseCanonicalName Off
# include the server name in the filenames used to satisfy requests
VirtualDocumentRoot /Users/hugowett/Projects/%0/public_html
<Directory "/Users/hugowett/Projects">
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Unfortunately you will have to edit Drupal’s .htaccess file for this to work with clean urls. Uncomment the RewriteBase / directive as we are running Drupal from a virtual document root from now on.
# If your site is running in a VirtualDocumentRoot at http://example.com/,
# uncomment the following line:
# RewriteBase /
The only thing that’s missing now is to configure bind for my mac so that I can add a .dev zone with a *.dev wildcard record. Any hints on how to do this would be greatly appreciated. Take a look here to configure bind on you mac, don’t use your IP for the A-records on MacBook though, use 127.0.0.1 instead.
Här var det tomt!
Ingen har skrivit en kommentar på den här artikeln. Bli den första!