DeveloperSide.NET Forums

DeveloperSide.NET => Web.Developer Server Suite Community Edition,
Public Support Forum => Topic started by: admin on July 24, 2007, 03:33:53 AM



Title: This is how to set up Virtual Hosts [VitrualHosting] under Apache...
Post by: admin on July 24, 2007, 03:33:53 AM
To set up Virtual Hosts under Apache...

Do this in one of two ways...

Method 1) Edit \www\Apache22\conf\httpd.conf with the following code.

Method 2) Uncomment line '#Include conf/extra/httpd-vhosts.conf' under \www\Apache22\conf\httpd.conf, delete everything under \www\Apache22\conf\extra\httpd-vhosts.conf [it's all dummy template-like code], and insert the following code into this file.

Notes:
  • 1. This will create two name-based Virtual Hosts, 'host1.net' and 'host2.net'
  • 2. DO NOT SUBSTITUTE YOUR IP, OR ANY IP, FOR THE '*:80' PART.
  • 3. The actual VH directories must go outside of our webroot [DocumentRoot], I'll place them under \www\vhosts\. Otherwise, this will not work.

Code:
NameVirtualHost *:80

<VirtualHost *:80>
ServerName  host1.net
ServerAlias www.host1.net
DocumentRoot /www/vhosts/host1.net
ErrorLog /www/Apache22/logs/error.log

        <Directory "/www/vhosts/host1.net">
                Options All
                AllowOverride All
                order allow,deny
                allow from all

AddType text/html .php .phps
AddHandler application/x-httpd-php .php
AddHandler application/x-httpd-php-source .phps

        </Directory>
</VirtualHost>

<VirtualHost *:80>
ServerName  host2.net
ServerAlias www.host2.net
DocumentRoot /www/vhosts/host2.net
ErrorLog /www/Apache22/logs/error.log

        <Directory "/www/vhosts/host2.net">
                Options All
                AllowOverride All
                order allow,deny
                allow from all

AddType text/html .php .phps
AddHandler application/x-httpd-php .php
AddHandler application/x-httpd-php-source .phps

        </Directory>
</VirtualHost>


If you use 'Options None, AllowOverride None' note that:

If you want mod_rewrite to work under these VHs, add line...

Code:
Options +FollowSymLinks

...within the Directory blocks.

If you want for .htaccess files to work under these VHs, add this somewhere [outside the VH block for global scope, within for local VH scope, within the Dirs for local per-dir scope, etc...]...

Code:
AccessFileName .htaccess

<Files ~ "^\.htaccess$">
   order allow,deny
   deny from all
</Files>

And add this line within the Directory blocks...

Code:
AllowOverride All

Final Note: If you use an ErrorLog directory other than the already present /www/Apache22/logs/, make sure to create the actual directory used or Apache will not start. For some reason Apache will also not show an error for this under error.log.


Title: Re: This is how you set up Virtual Hosts...
Post by: admin on July 25, 2007, 06:22:08 PM
Also note that aside from uncommenting the above httpd-vhosts.conf line under httpd.conf, there is nothing else you need to change under this configuration file.

Leave 'ServerName localhost:80', 'DocumentRoot "/www/webroot"', etc, alone. The individual VHs will use their own local values.


Title: Re: This is how you set up Virtual Hosts...
Post by: admin on July 28, 2007, 04:39:11 AM
When debugging problems, run 'httpd -S' from a dos box to see if Apache is actually getting the VHs.


Title: Re: This is how you set up Virtual Hosts...
Post by: majika on August 08, 2007, 09:27:47 PM
Hi,

Cheers Admin, I think i have cracked it, just found it a bit mind bending trying to get to grips with the concept of virtual hosts. 

I didn't realise that the VHosts DocumentRoot MUST be outside of the Servers DocumentRoot.

So just to ask the obvious question to you all, what is the advantages 'Or' what is VHosting used for in the hosting industry?

Like is it so that you can serve users with content from multiple sites under one server (localhost) without it all getting mixed up and stuff.

Also, is it also possible to use ReWrite Rule to further customize URL responces from server how exactly do you manipulate the URL's in the Virtualhost context?  If you are already using (astrix *):80 for the Virtualhost how would rewrite rule work if its already listening for all connections to that vhost ?




Title: Re: This is how you set up Virtual Hosts...
Post by: admin on August 08, 2007, 09:58:59 PM
Quote
So just to ask the obvious question to you all, what is the advantages 'Or' what is VHosting used for in the hosting industry?

In the absence of VirtualHosting, only 1 site/domain can be served per running instance of Apache.

With VH enabled, you can run many sites/domains under 1 Apache instance.

With only one IP address, and multiple sites, the only way for Apache to tell which site the client is requesting is to check the HOST header sent under HTTP v1.1 [not present under v1.0]... And thats where VirtualHosting takes over.

Quote
Also, is it also possible to use ReWrite Rule to further customize URL responces from server how exactly do you manipulate the URL's in the Virtualhost context?

You use mod_rewrite under VHs exactly like you use it under the global scope... Just enable and put your rules in the specific VH block, and there is nothing more to worry about. In that block Apache will only see requests for that specific domain.


Title: Re: This is how you set up Virtual Hosts...
Post by: CareyB on August 09, 2007, 12:12:51 PM
I apologize to our buddy, admin, for this, but it's not that tough to set up virtual hosts.  Here's a dead minimum how to:

Clip from httpd-vhosts.conf
Code:
<VirtualHost *:80>
   DocumentRoot /www/webroot/
   ServerName localhost
</VirtualHost>
<VirtualHost *:80>
    DocumentRoot /www/webapps/drupal/
    ServerName bingo
</VirtualHost>
<VirtualHost *:80>
    DocumentRoot /www/webroot/bango/
    ServerName bango
</VirtualHost>

Note that my 'bango' host is within the main document root.  The keys are that the path must be a real path, and you must set up a virtual host for localhost.

When you turn on virtual hosts, if you still want to serve from the default setup/doc root, you must have a virtual host for that.  Essentially, if you turn on virtual hosting, Apache wants to do things only that way.  There's more to it than that, but read the actual Apache docs regarding this: http://httpd.apache.org/docs/2.2/vhosts/name-based.html

Note that bingo is served from the Drupal directory for a document root.  From there Drupal takes over rewriting URL's, if you have a separate site set up for bingo, otherwise you just get the default Drupal site.

Note that you must add to the windows 'hosts' file thus:
Clip from C:\windows\system32\drivers\etc\hosts
127.0.0.1       localhost
127.0.0.1       bango
127.0.0.1       bingo

Clip output from the httpd -S command
Code:
C:\Documents and Settings\CareyB>httpd -S
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80                   is a NameVirtualHost
         default server localhost (D:/www/Apache22/conf/extra/httpd-vhosts.conf:44)
         port 80 namevhost localhost (D:/www/Apache22/conf/extra/httpd-vhosts.conf:44)
         port 80 namevhost bango (D:/www/Apache22/conf/extra/httpd-vhosts.conf:48)
         port 80 namevhost bingo (D:/www/Apache22/conf/extra/httpd-vhosts.conf:52)
Syntax OK

Using the 'httpd -S' command in a terminal window is very helpful.  Note that this checks the syntax of the configuration files, and that Apache does not need to be running for it to work.

Note that 'httpd -h' will show you all the options available.  Since I have the terminal window open, I find 'httpd -k restart' to be very handy.


Title: Re: This is how you set up Virtual Hosts [VitrualHosting] under Apache...
Post by: admin on August 09, 2007, 02:11:03 PM
Those are all good points...

You can run VHs in the global documentroot after all... As long as you have a localhost VH block as the 1st VH block read by Apache. Though I would be careful with this as I see many ways someone new can run into problems.

I will consider adding...
Quote
<VirtualHost *:80>
   DocumentRoot /www/webroot/
   ServerName localhost
</VirtualHost>
...to our Suite setup without any other further code within the VH block, purely for semantical reasons.


Title: Re: This is how you set up Virtual Hosts [VitrualHosting] under Apache...
Post by: night2dark2 on August 09, 2007, 02:54:44 PM
Use

Code:

<VirtualHost *:80>
ServerName domain1.tld
DocumentRoot "/www/Vhost/domain1.tld/"

<Directory "/www/Vhost/domain1.tld/">
   Order Allow,Deny
   allow from All
</Directory>

</VirtualHost>


Title: Re: This is how to set up Virtual Hosts [VitrualHosting] under Apache...
Post by: Wilz on August 17, 2007, 11:38:46 AM
Admin, I've change my vhost config file to look like what is shown below-

<VirtualHost *:80>
    ServerName gamesgalore.servegame.org
    ServerAlias www.gamesgalore.servegame.org
    ServerAdmin admin@gamesgalore.servegame.org
    DocumentRoot /www/vhost/arcade
    ErrorLog /www/vhost/arcade/logs/error.log
 
    <Directory "/www/vhost/arcade">
         Options +FollowSymlinks
         AllowOverride All
         Order allow,deny
         Allow from all


               AddType text/html .php .phps
      AddHandler application/x-httpd-php .php
      AddHandler application/x-httpd-php-source .phps


    </Directory>
</VirtualHost>
AccessFileName .htaccess

<Files ~ "^\.htaccess$">
   order allow,deny
   deny from all
</Files>

which is pretty much what you had said. My problem is that now I can't browse that directory using the URL, http://localhost/vhost/arcade/install.php, so I can reinstall the script. When I used my old settings which is below-

<VirtualHost *:80>
    ServerAdmin admin@arcade.gamesgalore.servegame.org
    DocumentRoot /www/webroot/arcade
    ServerName www.gamesgalore.servegame.org
    ErrorLog logs/arcade-error_log
    <Directory "/www/webroot/arcade">
         Options Indexes FollowSymLinks
         AllowOverride None
         Order allow, deny
         Allow from all
    </Directory>
</VirtualHost>

I was able to install the web script using a URL, http://localhost/arcade/install.php. Would you be able to assist me in figuring out how this could happen.
Oh and I have tryed to use different url address to see how I can reach the directory from a localhost perspective but to no avail. I also haven't edited the httpd.conf file like you said in your post.

cheers


Title: Re: This is how to set up Virtual Hosts [VitrualHosting] under Apache...
Post by: admin on August 17, 2007, 12:59:49 PM
gamesgalore.servegame.org/install.php is the URL and not localhost/vhost/arcade/install.php


Title: Re: This is how to set up Virtual Hosts [VitrualHosting] under Apache...
Post by: Wilz on August 17, 2007, 06:44:43 PM
Hello again admin, well I tryed everything you had in your post but I can't seem to be able to the directory from the computer that hosts the server. Any way I also tryed to do what carey B had in his/her post. If you have any suggestions I'd be much appreciative but if not, all good. I think I'll just use the webroot for my vhosts. Anyway I do have a problem using vhost under the webroot directory, it seems that every time I put the http//gamesgalore.servegame.org URL in the browser from an outside computer, I seem to get the directory listing's of my vhost directory. It's not until I type, http://gamesgalore.servegame.org/arcade URL, that I get the right directory, any suggestions. Also just for the records my server is installed on D:\ drive and not C:\ (seperate drive from system drive), if that matters any.


Title: Re: This is how to set up Virtual Hosts [VitrualHosting] under Apache...
Post by: night2dark2 on August 24, 2007, 01:07:26 AM
it doesn't really matter because Apache reads your from your %...% dir which should be your WinInstall Drive :)


Title: Re: This is how to set up Virtual Hosts [VitrualHosting] under Apache...
Post by: cyrusnguyen on October 18, 2007, 07:41:03 PM
done everything the way it suppose to be....two websites....website 1 works fine....but when i enter in the domain for website 2, it resolves to website 1.


Title: Re: This is how to set up Virtual Hosts [VitrualHosting] under Apache...
Post by: night2dark2 on October 26, 2007, 10:57:47 PM
hmm , I had to VHost all my sites including localhost. but they all work. And your probally not doing the correct syntax.


Title: Re: This is how to set up Virtual Hosts [VitrualHosting] under Apache...
Post by: astrothug on November 12, 2007, 06:34:26 AM
so will this not work on a newer server package ?

Quote
<VirtualHost 209.145.106.99:80>
ServerName www.ghostintheshell.ca
ServerAlias  ghostintheshell.ca  *. ghostintheshell.ca
DocumentRoot /www/webroot/site1
</VirtualHost>
 
<VirtualHost 209.145.106.99:80>
ServerName arcade.ghostintheshell.ca
DocumentRoot /www/webroot/site1/arcade
</VirtualHost> 

<VirtualHost 209.145.106.99:80>
ServerName shane.ghostintheshell.ca
DocumentRoot /www/webroot/site1/shane
</VirtualHost> 

<VirtualHost 209.145.106.99:80>
ServerName home.ghostintheshell.ca
DocumentRoot /www/webroot/site1/home
</VirtualHost> 

<VirtualHost 209.145.106.99:80>
ServerName davidwatson.no-ip.com
DocumentRoot /www/webroot/site2
</VirtualHost>

<VirtualHost 209.145.106.99:80>
ServerName butterfly69.com
DocumentRoot /www/webroot/site3
</VirtualHost>

<VirtualHost 209.145.106.99:80>
ServerName www.butterfly69.com
DocumentRoot /www/webroot/site3
</VirtualHost>

<VirtualHost 209.145.106.99:80>
ServerName rupertchat.no-ip.org
DocumentRoot /www/webroot/site4
</VirtualHost>

<VirtualHost 209.145.106.99:80>
ServerName www.kaienislandwolves.com
DocumentRoot /www/webroot/site5
</VirtualHost>


Title: Re: This is how to set up Virtual Hosts [VitrualHosting] under Apache...
Post by: admin on November 12, 2007, 12:53:30 PM
From a copy/paste... No.

There is no more webroot in Suite 2.0. Everything is Virtual Host centric... \www\vhosts\xxx

Create your sites under \www\vhosts\xxx, update \www\Apache22\conf\extra\httpd-vhosts.conf with the new vhost blocks.


Title: Re: This is how to set up Virtual Hosts [VitrualHosting] under Apache...
Post by: Jonpopnycorn on November 25, 2007, 06:18:37 AM
I can visit http://subdomain.mymainurl.com/ but I can't visit http://www.subdomain.mymainurl.com/

On the main domain it works perfect
http://mymainurl.com/ & http://www.mymainurl.com/ - works
http://subdomain.mymainurl.com/ - works
http://www.subdomain.mymainurl.com/ - don't work - Error: "Server not found"


My domain name is from godaddy.com

Code:
<VirtualHost *:80>
ServerName mymainurl.com
ServerAlias www.mymainurl.com
DocumentRoot /www/vhosts/www.mymainurl.com
ErrorLog /www/Apache22/logs/error.log

<Directory "/www/vhosts/www.mymainurl.com">
Options All
AllowOverride All
order allow,deny
allow from all
</Directory>
</VirtualHost>

<VirtualHost *:80>
ServerName subdomain.mymainurl.com
ServerAlias www.subdomain.mymainurl.com
DocumentRoot /www/vhosts/subdomain.mymainurl.com
ErrorLog /www/Apache22/logs/error.log

<Directory "/www/vhosts/subdomain.mymainurl.com">
Options All
AllowOverride All
order allow,deny
allow from all
</Directory>
</VirtualHost>

Thanks, Jonpopnycorn


Title: Re: This is how to set up Virtual Hosts [VitrualHosting] under Apache...
Post by: admin on November 25, 2007, 03:08:37 PM
Sounds like you might not have created the DNS/HOST entry for 'www.sub...' with your registrar/godaddy. Or that it's pointing to the wrong IP or name server.


Title: Re: This is how to set up Virtual Hosts [VitrualHosting] under Apache...
Post by: Jonpopnycorn on November 26, 2007, 03:22:58 AM
Oh ok, I didn't know we had to add an extra CNAME for it. Thanks for telling :)


Title: Re: This is how to set up Virtual Hosts [VitrualHosting] under Apache...
Post by: inmrc on March 16, 2008, 03:53:13 PM
This has to be the best wamp setup ever.
Now the only problem I have is how to add another Drupal site

It seems to be treated differently that other Vhosts. and needs to use the .htaccess file for mod rewrite.

This is the output from
C:\Documents and Settings\inmrc>httpd -S
Warning: DocumentRoot [C:/www/vhosts/omwb.com] does not exist
Warning: DocumentRoot [C:/www/vhosts/host2.tld] does not exist
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80                   is a NameVirtualHost
         default server localhost (C:/www/Apache22/conf/extra/httpd-vhosts.conf:32)
         port 80 namevhost localhost (C:/www/Apache22/conf/extra/httpd-vhosts.conf:32)
         port 80 namevhost host1.tld (C:/www/Apache22/conf/extra/httpd-vhosts.conf:48)
         port 80 namevhost host2.tld (C:/www/Apache22/conf/extra/httpd-vhosts.conf:64)
Syntax OK

The drupal doesn't show in the Vhost.config yet works perfectly including the clean URL's

May be you can explain or point me to the info on the use of suite-drupal.conf

Thanks for a great app
Ron


Title: Re: This is how to set up Virtual Hosts [VitrualHosting] under Apache...
Post by: admin on March 17, 2008, 07:18:16 PM
Its much easier to do in the upcoming version, but for now the simplest way is to create your newdomain dir under \www\vhosts\, create the vhost block under httpd-vhosts.conf, and just place another copy of drupal under \www\vhosts\newdomain\.


Title: Re: This is how to set up Virtual Hosts [VitrualHosting] under Apache...
Post by: inmrc on March 19, 2008, 01:47:50 PM
this is the VH File
#  www.vhosts\the-villages-online.com
<VirtualHost *:80>
   ServerName  the-villages-online.com
   ServerAlias www.the-villages-online.com
   DocumentRoot /www/vhosts/the-villages-online.com
   ErrorLog /www/Apache22/logs/error.log

   <Directory "/www/vhosts/the-villages-online.com">
      Options All
      AllowOverride All
      order allow,deny
      allow from all
   </Directory>
</VirtualHost>

I tried putting if in www/vhost/webapps and www/vhost

error message Not found on this server

httpd -S finds
#  www.vhosts\the-villages-online.com
         port 80 namevhost the-villages-online.com (C:/www/Apache22/conf/extra/h
ttpd-vhosts.conf:80)
Syntax OK

Where is the VH file for the Drupal?

Thanks
Ron


Title: Re: This is how to set up Virtual Hosts [VitrualHosting] under Apache...
Post by: admin on March 19, 2008, 10:24:39 PM
Did you add this domain to the Windows HOSTS file?


Title: Re: This is how to set up Virtual Hosts [VitrualHosting] under Apache...
Post by: inmrc on March 20, 2008, 12:55:09 AM
I did and then when I went to access the real site it had a conflict. I try to use the same name a the production site so the path's don't get messed up. I will try it with out the ".com"

So how does the first drupal site get resolved, I culd not find a VH file for it?

Thanks
Ron



Title: Re: This is how to set up Virtual Hosts [VitrualHosting] under Apache...
Post by: garek007 on March 20, 2008, 11:12:32 PM
I've tried everything and I can't get other virtual hosts setup.  I've done exactly what was noted above, yet still nothing.  What could i be doing wrong? here is the code in httpd-vhosts.conf

<VirtualHost *:80>
   ServerName  dahlingroup
   
   DocumentRoot /www/vhosts/host1.tld/
   ErrorLog /www/Apache22/logs/error.log

        <Directory "/www/vhosts/host1.tld/">
                Options All
                AllowOverride All
                order allow,deny
                allow from all

      AddType text/html .php .phps .html
      AddHandler application/x-httpd-php .php
      AddHandler application/x-httpd-php-source .phps

        </Directory>
</VirtualHost>

and I added this line

127.0.0.1   dahlingroup

in the hosts file as well.  Do I need to restart or something?


Title: Re: This is how to set up Virtual Hosts [VitrualHosting] under Apache...
Post by: admin on March 21, 2008, 03:57:22 AM
You need to restart Apache after configuration changes. And if you are using IE, you need to restart it and reload the page after hosts file changes. What does error.log show?


Title: Re: This is how to set up Virtual Hosts [VitrualHosting] under Apache...
Post by: garek007 on March 21, 2008, 03:32:29 PM
Okay I did what you said and this came up after I reloaded the page

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, admin@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.


--------------------------------------------------------------------------------

Apache/2.2.6 (Win32) mod_ssl/2.2.6 OpenSSL/0.9.8g PHP/5.2.5 Server at dahlingroup Port 80