Apache virtual host pointing to wrong document root

apache-2.2virtualhost

I am running Linux mint and I'm trying to setup up a virtual host with apache.

I have added the following file in /etc/apache2/sites-available/ ( it's copied from the 'default' file in that directory)

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName testsite.dev
        DocumentRoot /home/chris/Projects/web/testsite

        <Directory /home/chris/Projects/web/testsite>
            Allow from all
            AllowOverride All
            Order allow,deny
        </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
            AllowOverride None
            Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
            Order allow,deny
            Allow from all
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/access.log combined

        Alias /doc/ "/usr/share/doc/"
        <Directory "/usr/share/doc/">
            Options Indexes MultiViews FollowSymLinks
            AllowOverride None
            Order deny,allow
            Deny from all
            Allow from 127.0.0.0/255.0.0.0 ::1/128
        </Directory>
    </VirtualHost>

I have also added an entry in my hosts file (/etc/hosts) which would be:

127.0.0.1    testsite.dev

I've also enabled the site and reloaded the apache service with:

a2ensite testsite 
service apache2 reload

However when I browse to http://testsite.dev it's serving pages from /var/www/ instead of /home/chris/Projects/web/testsite.

What am I doing wrong?

Best Answer

A few things I would check:

  • Ensure that you have a "NameVirtualHost ***:80" in your config. If the "*:80" is different it may conflict with the value in "VirtualHost" (in general there are less issues if they are the same).
  • Ensure you don't have other "VirtualHost" defined somewhere that may be conflicting with this one (I assume everything in "sites-available" as well as any other Apache config file).
  • Check the error log to make sure nothing "bad" is happening. Enabling and checking the access log may also be useful.
  • Double check that the files/content in the two directories is what you think it is. If you have them somehow mixed up it could be working as expected.
  • Stop and start Apache service. In theory reloading should work but just in case (it wouldn't be the first time I've seen reloading fail but stopping/starting work).

If you run through all this and still can't seem to get what you want I would create a minimal set of Apache configs (move all existing configs out and create temporary ones) and start changing things a step at a time to see where things are going wrong.