Community Documentation

Installing virtual hosts for Drupal sites and subsites

Last updated September 20, 2008. Created by betz on January 20, 2007.
Edited by kanani, sepeck, tarek. Log in to edit this page.

The purpose of this guide is to concisely summarize how to implement apache vhost settings for each site or subsite.

All steps for this tutorial were implemented with Debian using Apache version 2.0.54.

  1. Gain entrance into your shell system, and su to root or another user that can edit apache2 configuration files.
  2. Go to your apache configuration files:
    cd /etc/apache2/sites-available
  3. Create a configuration file for your new site. For an example site, www.example.com, we make the site as such:
    nano example.com

    <VirtualHost *:80>
        ServerAdmin me@myserver
        DocumentRoot /home/web/drupal/
        ServerName www.example.com
        ServerAlias example.com *.example.com
        RewriteEngine On
        RewriteOptions inherit
        CustomLog /var/log/apache2/example.com.log combined
    </VirtualHost>
    <VirtualHost *:443>
        ServerAdmin me@myserver
        DocumentRoot /home/web/drupal/
        ServerName www.example.com
        ServerAlias example.com *.example.com
        RewriteEngine On
        RewriteOptions inherit
        CustomLog /var/log/apache2/example.com.log combined
        # SSL Specific options
        SSLEngine on
        SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
        SSLCertificateFile /etc/ssl/apache/CA.crt
        SSLCertificateKeyFile /etc/ssl/apache/CA.key
        SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown
    </VirtualHost>
  4. Activate the site's configuration:
    a2ensite www.example.com
  5. Reload Apache's configuration:
    /etc/init.d/apache2 force-reload
  6. Done!

If you get an apache error '/home/www/drupal5/.htaccess: Option Indexes not allowed here'
Assuming that my apache2 DocumentRoot is at /home/www,
and that drupal is linked to the doc root by
ln -s /usr/share/drupal5 /home/www/

add the following to /etc/apache2/conf.d/drupal.conf

<Directory /home/www/drupal5/>
Options +FollowSymLinks Indexes
AllowOverride All
order allow,deny
allow from all
</Directory>

Comments

Worked for me. Thank you

Worked for me. Thank you very much. The only trouble was an apache error '/home/www/drupal5/.htaccess: Option Indexes not allowed here'
Assuming that my apache2 DocumentRoot is at /home/www,
and that drupal is linked to the doc root by
ln -s /usr/share/drupal5 /home/www/

my fix is adding the following to /etc/apache2/conf.d/drupal.conf

<Directory /home/www/drupal5/>
Options +FollowSymLinks Indexes
AllowOverride All
order allow,deny
allow from all
</Directory>

In actual fact, i found the above could replace the file /etc/apache2/conf.d/drupal.conf, as the old
contents didnt seem to do anything for me. It works either as an addition or a replacement for me.

Hmm...didn't work

I got an error saying:
"Syntax error on line 9 of /etc/apache2/sites-enabled/mysite: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration...fail"

Enable mod-rewrite on apache2

I realize this is a yr old necropost, but if anyone gets this error this may be helpful- I get this error also on new installs. You will have to enable mod-rewrite module in apache. It should be included with the package in debian/ubuntu, but by default is not enabled.

$ cd /var/apache2/mods-enabled
$ sudo ln -s ../mods-available/rewrite.load rewrite.load
$ sudo /etc/init.d/apache2 restart

Shell scripts for Drupal and virtual hosts install

The densite script (aka the a2ensite debian script) can be found at http://www.drupal.org/project/densite The densite script does the same things as the instructions given above (and some more: e.g. list your sites, populate database from a dump on install, or import dumps from other of your sites. It can also install directly via download and set up mysql or postgresql databases, setup the virtual host and then reload apache. It is intended to work out of the box on Debian machines. Just dump the densite folder in your drush command folder and it should work right away on Debian based machines (Tested on ubuntu .8.10 intreped and and Ubuntu 8.04 Hardy)

Installation guide

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.