I like to develop against local virtual hosts when I work with Drupal. Here is the apache httpd.conf configuration that has served me the best so far. The first VirtualHost is the default .. .simply replicate the second VirtualHost entry and edit accordingly. A simple edit of /etc/hosts to enter the virtual host name that matches the virtual host entries in the httpd.conf and a quick reload by apache and you are good to go. I particularly enjoy the independent logging for each site.
This is likely a no-brainer for the server admins out there but I remember a time when this type of information would have been useful to me ... so here it is. This is not a production level configuration. Have suggestions for improving it?
NameVirtualHost *
ServerName 127.0.0.1
<VirtualHost *>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/
<Directory />
Options FollowSymLinks
AllowOverride all
</Directory>
<Directory /var/www/>
Options All Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</Directory>
ErrorLog /var/log/apache2/error.log
LogLevel warn
CustomLog /var/log/apache2/access.log combined
ServerSignature Off
</VirtualHost>
<VirtualHost *>
ServerName mysite
DocumentRoot /var/www/mysite/trunk/htdocs
ErrorLog /var/log/apache2/mysite_error.log
CustomLog /var/log/apache2/mysite_access.log combined
</VirtualHost>
127.0.0.1 localhost.localdomain localhost mysite mysite1 mysite2
Comments
Best Practice
Here is an example of what I use:
ServerAdmin webmaster@domain.com
DocumentRoot /www/websites/domain.com
ServerName devel.domain.com
ServerAlias www.domain.com domain.com
ErrorLog logs/domain.com-error_log
In my hosts file:
127.0.0.1 devel.domain.com
Using the devel prefix is nice because then in your drupal sites folder you just need to create one domain.com folder with your settings.php file and it will catch both your development and live instances.
Here's a much easier way
Step 1:
Check out / download drupal and put it in /var/www/public_html/5.8 (or anywhere really)
Step 2: Make a symlink from 5-current -> 5.8 in that directory
Step 3: Create a file in your conf.d or sites-enabled called 5.conf :
ServerName 5
ServerAlias *5
DocumentRoot /var/www/public_html/5-current
Step 4:
in your hosts file, call all your 5.x sites {SITE}5. So I worked on amnesty, I called mine ai5:
127.0.0.1 localhost ai5
Step 5:
Make sure your site folder for that site is the same as your domain (duh).
Step 6:
There is no step 6. From now on, you just have to add a new site to the hosts file. The *5 in the ServerAlias matches any domain ending in 5!
(Creds to http://www.civicactions.com/team/owenbarton) for showing me this.
Doh! <code> not working
So, my last post looks a little funny because the >code< tag didn't work as promised. needless to say, there are VirtualHost tags around the snippit for 5.conf.
Easier way for OS X users
For those on OS X, use Patrick Gibson's script.
It's freakin sweet.
http://patrickgibson.com/utilities/virtualhost/
Drubuntu
Also, see Drubuntu Drupal group and their HOWTO.
Using the devel prefix is
Using the devel prefix is nice because then in your drupal sites folder you just need to create one domain.com folder with your settings.php file and it will catch both your development and live instances.