Page 1 of 1

How to create specific virtual hosts?

PostPosted: 07. January 2009 12:03
by spriteork
Hi all.
Please suggest me how to create specific virtual local hosts with specific address(for example www.spriteork.com) and specific folder for site(for example D:\site)

As I read Apache manual, i must edit
....\xampp\apache\conf\extra\httpd-vhosts.conf
I'm edit it, adding there all as wrote in manual, creating host folder, writing test file index.php with some php code, saving it in that folder. When trying to open virtual host in browser, but nothing happen, browser writes error "site not found"

Advance thanks for help

Re: How to create specific virtual hosts?

PostPosted: 07. January 2009 12:20
by Sharley
Please paste here your httpd-vhosts.conf file so we can see what you have done already - it will be easier to work with this file and paste back a possible solution.

A forum search for vhost or virtualhost will also give you many examples from the many previous posts on this subject.

Re: How to create specific virtual hosts?

PostPosted: 07. January 2009 12:28
by spriteork
I'm delete all that i add and restart xampp because virtual host didn't create
[httpd-vhosts.conf]
--------------------------------------------------------------------------------
#
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.2/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# Use name-based virtual hosting.
#
##NameVirtualHost *:80

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
##<VirtualHost *:80>
## ServerAdmin webmaster@dummy-host.example.com
## DocumentRoot /www/docs/dummy-host.example.com
## ServerName dummy-host.example.com
## ServerAlias www.dummy-host.example.com
## ErrorLog @rel_logfiledir@/dummy-host.example.com-error_log
## CustomLog @rel_logfiledir@/dummy-host.example.com-access_log common
##</VirtualHost>

##<VirtualHost *:80>
## ServerAdmin webmaster@dummy-host2.example.com
## DocumentRoot /www/docs/dummy-host2.example.com
## ServerName dummy-host2.example.com
## ErrorLog @rel_logfiledir@/dummy-host2.example.com-error_log
## CustomLog @rel_logfiledir@/dummy-host2.example.com-access_log common
##</VirtualHost>

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

Re: How to create specific virtual hosts?

PostPosted: 07. January 2009 12:47
by Sharley
Try this - just copy and paste over your existing httpd-vhost.conf file.

I am assuming that XAMPP is in the default location C:\xampp
If not change the first DocumentRoot to your own path to htdocs.
Code: Select all
#
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.2/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# Use name-based virtual hosting.
#
##NameVirtualHost *:80

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
##<VirtualHost *:80>
##    ServerAdmin webmaster@dummy-host.example.com
##    DocumentRoot /www/docs/dummy-host.example.com
##    ServerName dummy-host.example.com
##    ServerAlias http://www.dummy-host.example.com
##    ErrorLog @rel_logfiledir@/dummy-host.example.com-error_log
##    CustomLog @rel_logfiledir@/dummy-host.example.com-access_log common
##</VirtualHost>

##<VirtualHost *:80>
##    ServerAdmin webmaster@dummy-host2.example.com
##    DocumentRoot /www/docs/dummy-host2.example.com
##    ServerName dummy-host2.example.com
##    ErrorLog @rel_logfiledir@/dummy-host2.example.com-error_log
##    CustomLog @rel_logfiledir@/dummy-host2.example.com-access_log common
##</VirtualHost>

NameVirtualHost *:80

<VirtualHost *:80>
ServerName localhost
DocumentRoot "C:/xampp/htdocs"
</VirtualHost>

<VirtualHost *:80>
ServerName spriteork.com
ServerAlias www.spriteork.com
DocumentRoot "D:/site"
<Directory "D:/site" >
Options Indexes +FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Save the file and restart Apache.

If it won't start double click on the .\xampp\apache_start.bat file and it will give you a detailed error message.

EDIT
Syntax error fixed - sorry didn't proof read correctly, in too much of a hurry. tut tut.

Re: How to create specific virtual hosts?

PostPosted: 07. January 2009 14:05
by spriteork
He wrote error when I launch apache:
----------------------------------------------------------------------------------------------------
Apache 2 is starting ...
apache.exe: Syntax error on line 502 of D:/xampp/apache/conf/httpd.conf: Syntax
error on line 49 of D:/xampp/apache/conf/extra/httpd-vhosts.conf: Expected </Vir
tualHost> but saw </Directory>

Apache konnte nicht gestartet werden
Apache could not be started
Press any key for continue
-----------------------------------------------------------------------------------------------------

Re: How to create specific virtual hosts?

PostPosted: 07. January 2009 14:10
by Nobbie
You must also assign a valid IP to the domain http://www.spriteork.com

If you dont have registered this domain via a public DNS provider, you must supply the IP on your own (but is valid only for your local PC or your LAN). Therefore you have to edit the file c:\windows\system32\drivers\etc\hosts and append the following line:

127.0.0.1 http://www.spriteork.com

There is no need to restart Apacher neither to reboot the PC, simply enter http://www.spriteork.com in your browser and see what happens.

Re: How to create specific virtual hosts?

PostPosted: 07. January 2009 14:15
by spriteork
Where i must paste this string "127.0.0.1 http://www.spriteork.com"?

Re: How to create specific virtual hosts?

PostPosted: 07. January 2009 14:16
by glitzi85
The error you get while starting comes from an mistake in the configuration posted by Sharley. Replace

Code: Select all
<VirtualHost *:80>
ServerName localhost
DocumentRoot "C:/xampp/htdocs"
</Directory>
</VirtualHost>


with

Code: Select all
<VirtualHost *:80>
ServerName localhost
DocumentRoot "C:/xampp/htdocs"
</VirtualHost>


glitzi

PS: Paste the Line in the File posted by Nobbie!

Re: How to create specific virtual hosts?

PostPosted: 07. January 2009 14:16
by spriteork
Ok, understand, try to do it

Re: How to create specific virtual hosts?

PostPosted: 07. January 2009 14:26
by spriteork
Writes error, Apache don't launching:
------------------------------------------------------------------------------
Diese Eingabeforderung nicht waehrend des Running beenden
Bitte erst bei einem gewollten Shutdown schliessen
Please close this command only for Shutdown
Apache 2 is starting ...
(OS 10048)╬с√ўэю ЁрчЁх°рхЄё  юфэю шёяюы№чютрэшх рфЁхёр ёюъхЄр (яЁюЄюъюы/ёхЄхтющ
рфЁхё/яюЁЄ). : make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs

Apache konnte nicht gestartet werden
Apache could not be started
Press any key for continue....
-----------------------------------------------------------------------------

Re: How to create specific virtual hosts?

PostPosted: 07. January 2009 14:37
by spriteork
All start work after adding host to D:\WINDOWS\system32\drivers\etc\hosts

Thank you all