DeveloperSide.NET Forums
September 22, 2019, 05:56:04 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1] 2
  Print  
Author Topic: This is how to set up Virtual Hosts [VitrualHosting] under Apache...  (Read 68813 times)
0 Members and 1 Guest are viewing this topic.
admin
Administrator
Master of All Subjects
*****
Posts: 3272


View Profile WWW Email
« 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.
« Last Edit: August 17, 2007, 01:03:20 PM by admin » Logged

DeveloperSide.NET
Advanced PHP and MySQL Solutions for your Web Design and Development needs with Web.Developer Server Suite.
admin
Administrator
Master of All Subjects
*****
Posts: 3272


View Profile WWW Email
« Reply #1 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.
Logged

DeveloperSide.NET
Advanced PHP and MySQL Solutions for your Web Design and Development needs with Web.Developer Server Suite.
admin
Administrator
Master of All Subjects
*****
Posts: 3272


View Profile WWW Email
« Reply #2 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.
Logged

DeveloperSide.NET
Advanced PHP and MySQL Solutions for your Web Design and Development needs with Web.Developer Server Suite.
majika
Member
*
Posts: 14


View Profile
« Reply #3 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 ?


« Last Edit: August 08, 2007, 09:32:02 PM by majika » Logged
admin
Administrator
Master of All Subjects
*****
Posts: 3272


View Profile WWW Email
« Reply #4 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.
« Last Edit: August 09, 2007, 01:46:34 PM by admin » Logged

DeveloperSide.NET
Advanced PHP and MySQL Solutions for your Web Design and Development needs with Web.Developer Server Suite.
CareyB
Member
*
Posts: 1


View Profile Email
« Reply #5 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.
Logged
admin
Administrator
Master of All Subjects
*****
Posts: 3272


View Profile WWW Email
« Reply #6 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.
« Last Edit: August 09, 2007, 02:57:28 PM by admin » Logged

DeveloperSide.NET
Advanced PHP and MySQL Solutions for your Web Design and Development needs with Web.Developer Server Suite.
night2dark2
Jr. Member
**
Posts: 98


Yeah Dont really ask.

mfaiotto@msn.com
View Profile WWW
« Reply #7 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>
Logged

Revolution Gamers Host.
Master of all Gunz Server Hosting Needs.
Revolution Gamers International Gaming Commmunity
Wilz
Member
*
Posts: 26


View Profile
« Reply #8 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
Logged
admin
Administrator
Master of All Subjects
*****
Posts: 3272


View Profile WWW Email
« Reply #9 on: August 17, 2007, 12:59:49 PM »

gamesgalore.servegame.org/install.php is the URL and not localhost/vhost/arcade/install.php
« Last Edit: August 17, 2007, 01:04:32 PM by admin » Logged

DeveloperSide.NET
Advanced PHP and MySQL Solutions for your Web Design and Development needs with Web.Developer Server Suite.
Wilz
Member
*
Posts: 26


View Profile
« Reply #10 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.
Logged
night2dark2
Jr. Member
**
Posts: 98


Yeah Dont really ask.

mfaiotto@msn.com
View Profile WWW
« Reply #11 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 :)
Logged

Revolution Gamers Host.
Master of all Gunz Server Hosting Needs.
Revolution Gamers International Gaming Commmunity
cyrusnguyen
Member
*
Posts: 3


View Profile
« Reply #12 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.
Logged
night2dark2
Jr. Member
**
Posts: 98


Yeah Dont really ask.

mfaiotto@msn.com
View Profile WWW
« Reply #13 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.
Logged

Revolution Gamers Host.
Master of all Gunz Server Hosting Needs.
Revolution Gamers International Gaming Commmunity
astrothug
Member
*
Posts: 15


View Profile Email
« Reply #14 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>
Logged
Pages: [1] 2
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.9 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!