# setting up Apache vhosts for subdomains [Invalid, Ignore]

## tkirby

Ok, I've been messing with apache configs for 5 hours now and it's just not working out.

I have a site set up and working with apache, we'll call it  'mywebsite.com'. It works and I couldn't be more pleased with it. Five hours ago, I came up with the notion that it would be cool to have a subdomain called 'dev.mywebsite.com' where I could clone my production site over and use it for development.

First step. I had my hosting provider set up DNS to route dev.mywebsite.com to my server and that worked like a champ. Next I tried typing 'dev.mywebsite.com' into the browser to see what apache would do with it and I got this in the error log: 

[Sun Apr 13 10:59:32 2008] [error] [client 86.75.30.9] File does not exist: /var/www/localhost/htdocs/dev, referer: http://dev.mywebsite.com/

So it looks like some helpful directive in the myriad of configuration and modules is trying to map dev.mywebsite.com to /var/www/localhost/htdocs/dev. This is nice but not exactly what I want. I'd rather it to go to /var/www/dev/htdocs so i don't have to worry about paths being different when I copy stuff back to my production site. I also want a separate cgi-bin and all that good stuff so /var/www/dev/htdocs is a much better choice.

So anyways, I tried about seventy-five thousand permutations of vhost files, config directives, apache restarts, tutorials, howtos, readmes, examples, forum posts, blog entries and even an old apache book from, like 1999... and I can't for the life of me get dev.mywebsite.com to point anywhere but /var/www/localhost/htdocs/dev.

W. T. F?

What is telling dev.mywebsite.com to map to /var/www/localhost/htdocs/dev? And more importantly where can I find this little tidbit of helpfulness so that I can #$^*! GET RID OF IT!??!

Thanks in advance for any elucidation.Last edited by tkirby on Sun Apr 20, 2008 11:38 pm; edited 1 time in total

----------

## elgato319

my guess is that you use apache2 on an up to date gentoo.

in /etc/apache2/httpd.conf there should be an entry:

```

Include /etc/apache2/vhosts.d/*.conf

```

i persume you have "-D DEFAULT_VHOST" already set in your /etc/conf.d/apache2

add a new vhost in /etc/apache2/vhosts.d. you can name it any way you want, but it needs to end with .conf

dev.mywebsite.com.conf

```

<VirtualHost *:80>

    ServerName dev.mywebsite.com

    DocumentRoot /var/www/dev.mywebsite.com/htdocs

    DirectoryIndex index.php index.html

    ErrorLog /var/www/dev.mywebsite.com/logs/error_log

    CustomLog /var/www/dev.mywebsite.com/logs/access_log combined

    <Directory "/var/www/dev.mywebsite.com/htdocs">

        Options -Indexes

        AllowOverride All

        Order allow,deny

        Allow from all

    </Directory>

    ScriptAlias /cgi-bin/ /var/www/dev.mywebsite.com/cgi-bin/

    <Directory "/var/www/dev.mywebsite.com/cgi-bin">

        Options ExecCGI

        AddHandler cgi-script .cgi .pl

        AllowOverride All

        Order allow,deny

        Allow from all

    </Directory>

</VirtualHost>

```

/var/www/dev.mywebsite.com should contain 3 dirs.

- htdocs

- logs

- cgi-bin

restart apache2 and try to access the vhost

----------

## tkirby

 *elgato319 wrote:*   

> my guess is that you use apache2 on an up to date gentoo.
> 
> Yep.
> 
> in /etc/apache2/httpd.conf there should be an entry:
> ...

 

Still the same deal.

Here's the output of running apache2 -S

```
wildcard NameVirtualHosts and _default_ servers:

_default_:443          localhost (/etc/apache2/modules.d/41_mod_ssl.default-vhost.conf:9)

*:80                   is a NameVirtualHost

         default server mywebsite.com (/etc/apache2/vhosts.d/00_default_vhost.conf:38)

         port 80 namevhost mywebsite.com (/etc/apache2/vhosts.d/00_default_vhost.conf:38)

         port 80 namevhost dev.mywebsite.com (/etc/apache2/vhosts.d/01_dev.mywebsite.com_vhost.conf:2)

Syntax OK
```

Does that look reasonable? The output is not all that readable. 

I'm gonna try running apache with strace to try to find out what is going on under the hood. This could really be made more transparent somehow.

----------

## tkirby

New info...

As a lark I tried hitting the site from my ssh session using lynx and it worked!?!?

lynx dev.mysite.com

I have no idea what that means or how to use it to fix this problem though.

----------

## xtz

Paster your vhost directives, please. I had the same problem 2 weeks ago.

----------

## tkirby

00_default_vhost.conf:

```
<IfDefine DEFAULT_VHOST>

Listen 80

NameVirtualHost *:80

<VirtualHost *:80>

    ServerName mywebsite.com

    Include /etc/apache2/vhosts.d/default_vhost.include

    <IfModule mpm_peruser_module>

        ServerEnvironment apache apache

    </IfModule>

</VirtualHost>

</IfDefine>

<IfDefine DEFAULT_VHOST>

```

default_vhost.include:

```
ServerAdmin root@localhost

DocumentRoot "/var/www/localhost/htdocs"

<Directory "/var/www/localhost/htdocs">

    Options Indexes FollowSymLinks

    AllowOverride All

    Order allow,deny

    Allow from all

</Directory>

<IfModule alias_module>

    ScriptAlias /cgi-bin/ "/var/www/localhost/cgi-bin/"

</IfModule>

<Directory "/var/www/localhost/cgi-bin">

    AllowOverride None

    Options None

    Order allow,deny

    Allow from all

</Directory>
```

01_dev.mywebsite.com_vhost.conf

```
<VirtualHost *:80>

   <VirtualHost *:80>

    ServerName dev.mywebsite.com

    DocumentRoot /var/www/dev.mywebsite.com/htdocs

    DirectoryIndex index.php index.html

    ErrorLog /var/www/dev.mywebsite.com/logs/error_log

    CustomLog /var/www/dev.mywebsite.com/logs/access_log combined

    <Directory "/var/www/dev.mywebsite.com/htdocs">

        Options -Indexes

        AllowOverride All

        Order allow,deny

        Allow from all

    </Directory>

    ScriptAlias /cgi-bin/ /var/www/dev.mywebsite.com/cgi-bin/

    <Directory "/var/www/dev.mywebsite.com/cgi-bin">

        Options ExecCGI

        AddHandler cgi-script .cgi .pl

        AllowOverride All

        Order allow,deny

        Allow from all

    </Directory>

</VirtualHost>

```

----------

## tkirby

This ended up being due to actions of my dns hosting co. They map all subdomains to dirctories under the main domains htdocs.

----------

