TUTORIAL: Setting Up Virtual hosts on Vista

Problems with the Windows version of XAMPP, questions, comments, and anything related.

TUTORIAL: Setting Up Virtual hosts on Vista

Postby idiotprogrammer » 10. October 2008 15:02

GOAL: Setting up fake domains for testing/development on a Vista machine.

Here is a brief how to set up virtual hosts on Vista. It may or may not be guaranteed to work on your system. However, it worked for me and I thought it worth sharing:

Assumptions:
you have installed Xampp on Vista and made sure to put the installation in a directory other than Program Files.
When you type http://localhost, you can reach the Xampp start screen (redirecting to http://localhost/xampp/ )
You have already set permissions by going to http://localhost/security/index.php so that your setup is secure.

Some details:

Where Things Are Your config files will be in this directory
C:\apache\xampp\apache\conf

However, if you want to create virtual hosts (that is, to go to www.myhost.com and www.myhost1.com on your local computer), the main file you will be editing will be C:\apache\xampp\apache\conf\extra\httpd-vhosts.conf

1. Before you do any editing, make a backup copy of httpd-vhosts.conf and htttpd.conf

2. Making sure your fake hosts resolve on your local machine. To do that, you need to edit your C:\WINDOWS\system32\drivers\etc\hosts file.

With Vista, there is a special trick. You can't merely doubleclick on the HOST file in Windows Explorer. You need to start Notepad first by rightclicking the Notepad shortcut on your Start menu and choosing "Run as Administrator". (This is a security mechanism that forces users to elevate privileges on the program itself). Hint: by default the Host file won't appear when you are browsing to that directory. You need to make sure that when you are browsing with the Open option that you not limit your searches to only txt files. To do that, change the filter in the Open window to All files (*.*)

Here is my host file. Note that I want to use a fake domain called http://read.local

Code: Select all
127.0.0.1       localhost
::1             localhost
127.0.0.1   read.local


3. Make sure you start Xampp as a Administrator. To do that, right-click the Xampp icon shortcut, and choose Run As Administrator.

4. Create a directory which you want to be your root for your fake host
I created I:\My Documents\websites\ and then I will be putting my directories for fake domains underneath it like this
I:\My Documents\websites\read.

5. Make sure to put an index.html or index.php file inside this new directory.

6. Edit your httpd-vhosts.conf file:

Here is mine:

Code: Select all
NameVirtualHost *:80

<VirtualHost *:80>
ServerName localhost
#DocumentRoot "C:/apache/xampp/htdocs" doesn't work
DocumentRoot "C:\apache\xampp\htdocs"
</VirtualHost>


<VirtualHost *:80>
ServerName read.local
DocumentRoot "I:\My Documents\websites\read"
#DocumentRoot "I:/My Documents/websites/read" doesn't work
ServerAdmin webmaster@dummy-host2.example.com
ErrorLog "C:\apache\xampp\apache\logs\read.local"
#<Directory "I:/MyDocuments/websites/read"> doesn't work
<Directory "I:\My Documents\websites\read">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>


Let's explain this.
a. NameVirtualHost *:80 is required. Here you are telling apache: hey, I want to associate multiple Internet host names with a single port/IP address.

b. When you use NameVirtualHost, you need to remind Apache how to get to the original htdocs root. Doing this will cause http://localhost to work as it did before you used virtual hosts/name based hosting. [/list]

c. I copied the file path from Windows Explorer. In other words, I went to the top address bar when I was in the right path in Windows Explorer and copied it. Note that I put everything inside quotation marks. That is required for Vista to be able to understand the path.


7. Open up a command line to doublecheck your syntax. This will catch the obvious errors.

Run, cmd, C:\apache\xampp\apache\bin\apache -t
(this will check your syntax)

Another helpful command to identify virtualhosting errors is apache -S

Other commands, try apache -h

I've been told that trying to start/stop apache via this command line does not work. You need to start it from the Xampp interface (or the Windows services menu if you have made it a Windows service).

8. Make sure your Xampp control panel is running as Administrator. (See step 3 above).

If Svc is unchecked, the Stop button will be visible. Stop apache, and then Start it.

(If you make apache a service, I think you need to stop/start under the Window services (in Administrative Tools on the control panel). But I prefer not to run it as a service.

9. After restarting apache using Xampp control panel, check http://localhost and http://read.local .

Other notes/suggestions:

1. if your browser shows an access problem, that probably means that the Windows path you have pasted is not correct (or not in quotations).

2. The log files are usually listed here C:\apache\xampp\apache\logs (If you want to keep a running view of a log file, download the freeware Baretail http://www.baremetalsoft.com/baretail/).
It is not necessary for you to create the log file. Apache will do it automatically for you.
It is possible to change the noiseness of your logs by editing httpd.conf file.

Code: Select all
# LogLevel: Control the number of messages logged to the error_log.
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
#
#LogLevel debug USE THIS TO HAVE VERBOSE ERROR MESSAGES
LogLevel warn


Important: Debug should only be used when testing. Normally you should only use warn or info.
idiotprogrammer
 
Posts: 6
Joined: 10. October 2008 01:31
Location: Houston, TX

Postby acambre » 31. October 2008 04:36

I am using XAMPP on Vista 32 bit which is mostly left in its default state for core OS settings. This means UAC is running as Microsoft intended.

I don't run control panel as administrator, and it works fine. After installing XAMPP and accepting all defaults, I can stop and start Apache and MySql just fine from the control panel with standard privileges.

My account is a member of the Vista machine's Administrators group. Is yours?
acambre
 
Posts: 5
Joined: 31. October 2008 04:31

Re: TUTORIAL: Setting Up Virtual hosts on Vista

Postby surfspot.de » 13. January 2009 11:06

Thanks for the tip about the backslash... I tried to use slashes like on my XP machine, and went just about nuts.

One problem still left though... how can I set up the vhost to point to my "Users" dir? When using "C:\Users\Myself\Open Projects\Testsite" as document root, Apache errors to "must be a directory"... in other words, doesn´t find or doesn´t have access to the "Users" directory. Running the xampp_start.bat as admin doesn´t change that behaviour at all, still no way to access the projects dir. Any ideas?!?

Should have kept the XP machine ;-)
surfspot.de
 
Posts: 1
Joined: 13. January 2009 10:54

Re: TUTORIAL: Setting Up Virtual hosts on Vista

Postby dmphotography » 14. January 2009 05:37

Now I'm curious, is there a way to use this method over a LAN or can it only be done on the host PC? I know you can use multiple ports over a LAN to achieve the same result or even over the WAN for that matter.
For great video and written tutorials and guides on creating your own web server and installing things such as forums, blogs, etc., visit http://myownhomeserver.com
dmphotography
 
Posts: 191
Joined: 15. December 2008 14:25
Location: Columbus, MS
XAMPP Version: 5.6.3
Operating System: Windows 7

Re: TUTORIAL: Setting Up Virtual hosts on Vista

Postby Izzy » 14. January 2009 05:59

surfspot.de wrote:One problem still left though... how can I set up the vhost to point to my "Users" dir? When using "C:\Users\Myself\Open Projects\Testsite" as document root, Apache errors to "must be a directory"... in other words, doesn´t find or doesn´t have access to the "Users" directory. Running the xampp_start.bat as admin doesn´t change that behaviour at all, still no way to access the projects dir. Any ideas?!?

Try and rename the folder with a space in the name to OpenProjects or Open_Projects as Apache on Vista may not like that as it has problems using the Program Files folder where permissions are an issue - only a suggestion and may be worth a try if all other avenues have been explored and keep in mind that Apache and most things XAMPP are case sensitive, folder is treated as a different folder to Folder and as is file.txt and FiLe.txt.

BTW I am curious about this back and forward slash issue as it would seem to be against the correct method used in Apache conf files and may simply be another Vista quirk - I hope W7 has all these mindless issues sorted out but if true MS form is anything to go by then they will sort these out but then give us some different quirks to contend with and to sort out in 7.

Can you please paste here line 42 or there abouts of your httpd.conf file on Vista installation? - ServerRoot line
Izzy
 
Posts: 3344
Joined: 25. April 2006 17:06

Re: TUTORIAL: Setting Up Virtual hosts on Vista

Postby dmphotography » 14. January 2009 09:37

Izzy wrote:Can you please paste here line 42 or there abouts of your httpd.conf file on Vista installation? - ServerRoot line


ServerRoot "C:/xampp/apache"

That's from a Vista Ultimate 64-bit install.
For great video and written tutorials and guides on creating your own web server and installing things such as forums, blogs, etc., visit http://myownhomeserver.com
dmphotography
 
Posts: 191
Joined: 15. December 2008 14:25
Location: Columbus, MS
XAMPP Version: 5.6.3
Operating System: Windows 7

Re: TUTORIAL: Setting Up Virtual hosts on Vista

Postby Izzy » 14. January 2009 10:10

dmphotography wrote:ServerRoot "C:/xampp/apache"

That's from a Vista Ultimate 64-bit install.
Hmm. Forward slashes and XAMPP in Vista 64 has no problems finding the Apache server.

Thanks for that and would you be so kind as to paste the DocumentRoot line please?
(line 182 in a default httpd.conf file)

I am assuming at this point it also has forward slashes but await your confirmation.
Thanks again.
Izzy
 
Posts: 3344
Joined: 25. April 2006 17:06

Re: TUTORIAL: Setting Up Virtual hosts on Vista

Postby longjefferson » 24. February 2009 08:19

Please visit.

URL:http://httpd.apache.org/docs/2.2/vhosts/

It is included in the folder C:\xampp\apache\conf\extra
:D :D :D
longjefferson
 
Posts: 1
Joined: 24. February 2009 08:14

Re: TUTORIAL: Setting Up Virtual hosts on Vista

Postby Izzy » 24. February 2009 08:31

longjefferson wrote:Please visit.
URL:http://httpd.apache.org/docs/2.2/vhosts/
It is included in the folder C:\xampp\apache\conf\extra
Is that so, well I never, fancy that, after all these years I must have missed it somehow. Image




No seriously now, back on topic.
@dmphotography - my request for how you have it configured ie. with forward slashes or with back slashes, as I still believe that forward slashes wrapped in quotes is the correct way not back slashes, but your input would be useful.
Izzy
 
Posts: 3344
Joined: 25. April 2006 17:06

Re: TUTORIAL: Setting Up Virtual hosts on Vista

Postby dalvan » 08. August 2009 20:59

Greetings- is anyone else having the problem of backslashes appearing at the end of the vhost name?

I get this everywhere:

<link rel="stylesheet" href="http://tbyte\/ etc.

all links, etc, the \ is thrown in after the virtual host name (tbyte)

this appears to have nothing to do with whether or not I use forward or backslashes in the vhosts conf file, or use a trailing slash at the end of the document root, etc. - it still just adds a backslash to the end of whatever i do. Here is what I have:

Code: Select all
NameVirtualHost *:80

<VirtualHost *:80>
ServerName localhost
#DocumentRoot "C:/apache/xampp/htdocs" doesn't work
DocumentRoot "C:\xampp\htdocs"
</VirtualHost>


<VirtualHost *:80>
ServerName tbyte
DocumentRoot "c:\xampp\htdocs\terabytedrives"

ErrorLog "C:\xampp\apache\logs\tbyte.error"
#<Directory "I:/MyDocuments/websites/read"> doesn't work
<Directory "c:\xampp\htdocs\terabytedrives">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>



strangely, localhost works fine, no problem

tbyte adds the backslashes.

Any ideas? thanks for your help
dalvan
 
Posts: 1
Joined: 08. August 2009 20:19

Re: TUTORIAL: Setting Up Virtual hosts on Vista

Postby nikfariz » 09. October 2009 17:38

I just solved a mystery..

Problem: Virtual host keeps redirecting to localhost/xampp despite changing the httpd-vhosts.conf and hosts files. For example, I tried http://sampleweb and it redirected me to http://sampleweb/xampp which shows the default page for xampp.

This is my original virtual host config (httpd-vhosts.conf):
Code: Select all
NameVirtualHost *:80

<VirtualHost *:80>
    ServerAdmin nikfariz@dotdot.com.my
    DocumentRoot "C:/xampp/htdocs"
    ServerName localhost
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin nikfariz@dotdot.com.my
    DocumentRoot "C:/xampp/htdocs/sampleweb"
    ServerName sampleweb
</VirtualHost>

and this is the hosts file from c:\windows\system32\drivers\etc\hosts
Code: Select all
127.0.0.1       localhost
::1             localhost
127.0.0.1 sampleweb


With this config, when I access http://sampleweb, it will always redirect to http://sampleweb/xampp. However, when I tried accessing my pc from another pc (by adding the following line in the hosts file of the other pc, assuming the IP of the webserver PC is 192.168.0.2), I was able to get to the sampleweb site (without any redirection to /xampp).

Code: Select all
127.0.0.1       localhost
::1             localhost
192.168.0.2 sampleweb


Now, it took me two days of trial and error when I suddenly felt the urge to make the following addition to my httpd-vhosts.conf file.

Code: Select all
NameVirtualHost *:80

<VirtualHost *:80>
    ServerAdmin nikfariz@dotdot.com.my
    DocumentRoot "C:/xampp/htdocs"
    ServerName localhost
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin nikfariz@dotdot.com.my
    DocumentRoot "C:/xampp/htdocs/sampleweb"
    ServerName sampleweb
</VirtualHost>

NameVirtualHost 127.0.0.1:80

<VirtualHost 127.0.0.1:80>
    ServerAdmin nikfariz@dotdot.com.my
    DocumentRoot "C:/xampp/htdocs"
    ServerName localhost
</VirtualHost>

<VirtualHost 127.0.0.1:80>
    ServerAdmin nikfariz@dotdot.com.my
    DocumentRoot "C:/xampp/htdocs/sampleweb"
    ServerName sampleweb
</VirtualHost>


Suddenly, my virtual website works on my (webserver) PC as well as any PCs trying to access this webserver PC. [Just be sure to restart apache after making the changes].

I never thought I could use more than one NameVirtualHost. But I guess, u never know unless you try.

If u are having the same problem as I did. Try this method. And let me know if it works..
nikfariz
 
Posts: 1
Joined: 09. October 2009 17:21

Re: TUTORIAL: Setting Up Virtual hosts on Vista

Postby Wiedmann » 10. October 2009 12:08

This is my original virtual host config (httpd-vhosts.conf):
Code: Select all
NameVirtualHost *:80

<VirtualHost *:80>
    ServerAdmin nikfariz@dotdot.com.my
    DocumentRoot "C:/xampp/htdocs"
    ServerName localhost
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin nikfariz@dotdot.com.my
    DocumentRoot "C:/xampp/htdocs/sampleweb"
    ServerName sampleweb
</VirtualHost>

and this is the hosts file from c:\windows\system32\drivers\etc\hosts
Code: Select all
127.0.0.1       localhost
::1             localhost
127.0.0.1 sampleweb


With this config, when I access http://sampleweb, it will always redirect to http://sampleweb/xampp.

Hm, I'm just test this with a clean new XAMPP installation exactly this configuration and was not be able to reproduce this behavior.
On my box:
a) "http://sampleweb/" is showing me the content from the directory "C:\xampp\htdocs\sampleweb"

b) and "http://localhost/" is redirecting me to "http://localhost/xampp/" and it's showing me the content from "C:\xampp\htdocs\xampp".

Exactly what I assume with this configuration. Maybe something in your "C:\xampp\htdocs\sampleweb" is the reason for this (wrong) redirect.
Wiedmann
AF Moderator
 
Posts: 17106
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Re: TUTORIAL: Setting Up Virtual hosts on Vista

Postby scathlock » 07. February 2010 21:42

I have the same problem as Dalvan - could You help us? Any ideas?
scathlock
 
Posts: 4
Joined: 07. February 2010 17:10

Re: TUTORIAL: Setting Up Virtual hosts on Vista

Postby karlw » 17. January 2013 19:58

In Windows 7 I kept getting "access forbidden" errors. Adding "Require all granted" to the <Directory> options resolved this (http://stackoverflow.com/questions/9110179/adding-virtualhost-fails-access-forbidden-error-403-xampp-windows-7).
A similar issue was getting perl scripts to run from afar. The simplest solution is to set up a symbolic link: C:\mklink /D usr C:\xampp\perl (http://www.codingforums.com/archive/index.php/t-159726.html). This will allow you to use the Linux shebang line without alteration.
There is no problem so simple I can't make it complicated. -Peanuts
karlw
 
Posts: 1
Joined: 17. January 2013 19:07
XAMPP Version: 5.6.3
Operating System: Windows 7

Re: TUTORIAL: Setting Up Virtual hosts on Vista

Postby JonB » 18. January 2013 00:19

In Windows 7 I kept getting "access forbidden" errors. Adding "Require all granted" to the <Directory> options resolved this (http://stackoverflow.com/questions/9110 ... -windows-7).


I should point out the issue you reference above is specific to Apache version 2.4.x and is due to the changes in the authorization methods for Apache and has nothing at all to do with the original post(s) - which were about Apache 2.2.x or how XAMPP works.

http://httpd.apache.org/docs/2.4/upgrading.html

The gist of these issues is also duly noted with stickies in the forums.

Good Luck to all.
:)
User avatar
JonB
AF Moderator
 
Posts: 3210
Joined: 12. April 2010 16:41
Location: Land of the Blazing Sun
XAMPP Version: 1.8.3-2
Operating System: Windows XP/7 - Fedora 15 1.7.7


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 46 guests