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

ArthurGruzauskas’s picture

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.

corydorning’s picture

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"

mchrisneglia’s picture

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

den.iver’s picture

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)

vyeluri’s picture

Following your steps I can able to access my website without /drupal in my url. Home page of my website is loaded but the images, links and drupal theme are broken.

Could you hep me with this issue, how can I load my website complete?

Thank you.

Hendrik53’s picture

Same with me.
I searched and tried everything. Bloth on a LAMP and a WAMP installation. I get the homepage, can work with admin instructions with Drupal 7 (uo-to-date). The site works on a hosting system. I use backup and restore module from Drupal. I copy all files and the backup file from the hosting service to my local host in a subdir under www. I've enabeled rewrite,. I've done the hosts file add lines and the apache ubuntu instructions that concern available sites.
The resulting pages show, but except pics and file references. These only work when I add the site-path (mysite) before the link that points towards the relative filepath.

What am I missing?
Status report is 100% ok. Settings.php host is pointing towards 'localhost'. Servername says 'mysite'. The virtualhost mapping directs to [drive]:\[path]\mysite.
When I try to edit the pic address, the browser shows up i the correct dir. The only change to be mde is the 'mysite' before the path that is shown as link.

Since this behavior is the same on LAMP and on WAMP, I think that some extra module or setting should be done. Can anyone help me?

sukh.singh’s picture

For Windows use the following directives

<Directory "c:/sites/drupal7/">
    AllowOverride All
    Allow from all
    Require local
</Directory>