This is driving me nuts. I’m trying to install XAMPP 1.4.2 (don’t ask, I’m not a programmer and I need to run a PHP4 app) and I can’t get virtual hosts to work. Now XAMPP 1.4.2 is supposed to have PHP4 and Apache 2.0 Problem is, no matter what, I can’t get name-based virtual hosts to work.
I have the correct entries in the hosts file, but the virtual hosts don’t work.
My httpd.conf is configured like this
# Use name-based virtual hosting.
#
NameVirtualHost *:80
I have 127.0.0.1 localhost and 127.0.0.1 yata4 in “hosts” and the paths are correct.
The problem is it doesn’ work properly. When typing http://localhost I get redirected to http://localhost/xampp/splash.php as expected. But when I go to http://yata4 I get the same content as that of the localhost (i.e. get redirected to http://yata4/xampp/splash.php) I’m at the end of my wits, I’ve read countless tutorials about name-based virtual hosts on the web and I couldn’t get any of them to work as expected. What am I doing wrong?
You need to make sure that your virtual hosts are configured exactly like the how you have the NameVirtualHost, as above.[COLOR=#003366][FONT=Courier New]
Well, while I loathe canned apps like this (and you’ve shown a good reason to install individual daemons, i.e., get the configuration you need), the answer lies in the httpd-vhosts.conf file (in the config/extras folder) and uncommenting the link to it in httpd.conf. That file will show you that you need something like
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
#
#<VirtualHost *>
# ServerAdmin [EMAIL="webmaster@dummy-host.example.com"]webmaster@dummy-host.example.com[/EMAIL]
# DocumentRoot /www/docs/dummy-host.example.com
# ServerName dummy-host.example.com
# ErrorLog logs/dummy-host.example.com-error_log
# CustomLog logs/dummy-host.example.com-access_log common
#</VirtualHost>
# Win32DisableAcceptEx ON
#
<VirtualHost *>
DocumentRoot c:/xampp/htdocs
ServerName localhost
</VirtualHost>
<VirtualHost yata4>
DocumentRoot c:/xampp/sites/yata4
ServerName yata4
</VirtualHost>
the problem is now that I added the yata4 virtual host, its contents also gets displayed when typing http://localhost in the address bar.
In case I wasn’t clear, if I type in http://yata4 i get the contents of that domain, and if I type in http://localhost I again get the contents of the yata4 subdomain (I checked). This isn’t what I expect, (what I had in mind was http://localhost would take to me to xampp/splash.php and typing yata4 would get me the contents of the yata4 virtual host. My set up seems correct, but it doesn’t work as expected.
The extras folder you mention does not exist in the install. I checked inside the zip archive to make sure.
To get around this issue you need to have ways to route to the two different sites yata4 and xampp/splash.php. To do this the easiest way is to set xampp as a virtual host as well. So it looks like:
For this you would need to type http://localhost to get to your splash page and http://yata4:800 (with the appended port) to get to your yata4 content.
Added the 127.0.0.1 xampp entry to the hosts file. Tried your exact config using c/p, it didn’t work, it caused 403 error forbidden, both on xampp, localhost and yata4.
Gets me a listing of the htdocs folder which has xampp and yata4 folders under it, regardless of whether I type xampp, localhost or yata4 in the address bar. So I’m kind of where I was before, as it is still treating all virtual hosts as identical. The reason I get the directory is probably because it now treats your directory index xampp.php as applying to all the virtual hosts even though it’s only defined for one of them. Unless you have another idea, I’ll probably be forced to dump this crap and install Apache and PHP manually, even though it’s a less elegant solution (I hate having to put php.ini inside the windows folder and all).
So you’re sure that you have xampp and yata4 defined in your hosts file or a local DNS? Your sure that you have Apache configured to use NamedVirtualHost for all hosts?
I run this same set-up although I installed Apache, MySQL separately and I have a host set on my DNS forwarder (PFSENSE firewall) and I have NamedVirtualHost set to true for all my hosts and this works.
This I no for certain. If you have a working host file or DNS that if you in a command line ping xampp and ping yata4 they return the right I.P. and you have Apache listening for Named Hosts then this should work. It just becomes like any other shared Apache server where you have different virtual hosts that represent different domain hosts.
Have you checked the permission of the XAMPP folder to see if the webserver has access to the \xampp\ folder and not just the \xampp\hotdocs\ folder?
Didn’t anyone read post #5? Just the code blocks in post #5? IMHO, you’ve butchered your <VirtualHost> block (at least for yata4) and have yet to display that you’ve updated the hosts file correctly.
I’ve already said that my C:\windows\system32\drivers\etc\HOSTS file has the following entries
# For example:
#
#102.54.94.97 rhino.acme.com # source server
#38.25.63.10 x.acme.com # x client host
127.0.0.1 localhost
::1 localhost
127.0.0.1 localhost
127.0.0.1 yata4
127.0.0.1 xampp
There are tabs between the IP and the name but they get stripped by the Sitepoint forum. <not if you put code tags around it the tabs are preserved>
Didn’t anyone read post #5? Just the code blocks in post #5? IMHO, you’ve butchered your <VirtualHost> block (at least for yata4) and have yet to display that you’ve updated the hosts file correctly.
Regards,
DK
I did. And I’ve already answered that the httpd-vhosts.conf does not exist, nor does the extra folder, even though that specific version is running apache 2.
Okay, the hosts file information looks correct but your VirtualHost is not. After class, please try to follow the format above and see if that doesn’t clear your problems.
No worries about the time delay. I’ve worked and taken grad classes until late at night. These days, I try to “have a life” and NOT sit on the computer (at least not at SitePoint) so I will generally only visit once a day … when I can.
On further thought, I can’t believe that XAMPP would modify the Apache conf files so massively as to eliminate the extras subdirectory, the httpd-vhosts.conf file and the link between the two at the end of the httpd.conf file. I believe you didn’t find them but please look again. If you have a good search function, search for <VirtualHost and it should show you your httpd.conf as well as the httpd-vhosts.conf files (perhaps even more files but I hope not).
I have used only the basic information required by the <VirtualHost> block and have provided that above. SPecifically, you’re lacking the IP address:port, the server name (in some) and the server path (in others). You should not repeat the localhost (which should be in the httpd.conf as it’s the default) and … well, as a student, I’ll ask you to check and match the format for your Virtual Hosts data. Should that fail, please post the revised code and I’ll help you get through it.
As an aside, the FREE chapter of Kevin Yank’s book is a great installation tutorial (albeit, the ancient version I first used was a bit out of order and WinDoze has changed drastically - keep out of the Program Files directory at all cost and be sure to specify the server correctly - 127.0.0.1 and localhost - when installing!). I prefer to install my daemons (MySQL, Apache, PHP and PHPMyAdmin - a great crutch for MySQL) individually rather than use a “canned app” like XAMPP but that was what you had specified.
On further thought, I can’t believe that XAMPP would modify the Apache conf files so massively as to eliminate the extras subdirectory, the httpd-vhosts.conf file and the link between the two at the end of the httpd.conf file. I believe you didn’t find them but please look again. If you have a good search function, search for <VirtualHost and it should show you your httpd.conf as well as the httpd-vhosts.conf files (perhaps even more files but I hope not).
Configuration files
File (Directory) \xampp\apache\conf\httpd.conf Usage The main configuration file for Apache. It’s including other files from the subdirectory “extra”.
keep out of the Program Files directory at all cost
That’s what I do most of the time, except for Microsoft Office.
I prefer to install my daemons (MySQL, Apache, PHP and PHPMyAdmin - a great crutch for MySQL) individually rather than use a “canned app” like XAMPP but that was what you had specified.
That’s how I used to do it on my old computer. Apache 1.3 and the zip version of PHP4. But that required me to place php.ini within the system path (more specifically inside the windows folder) which I never liked, and besides that meant I had to back up three different folders (C:\Mysql, C:\PHP - and most likely forget to back up c:\windows\php.ini! - and c:\apache. It would be more convenient to use XAMPP, provided I got it work, of course.
When you enable virtual hosting, Apache disables the main server root, so the first definition needs to reproduce the original server root. You then add each new virtual host within a pair of <VirtualHost> tags, using the location of the site’s web files as the value for DocumentRoot, and the name of the virtual host for ServerName. Again, use forward slashes, and if the path contains any spaces, enclose the whole path in quotes. If your server root is located, like mine, at C:\htdocs, and you are adding phpdw as a virtual host in C:\vhosts, change the code shown on lines 27 through 42 so they look like this (in XAMPP, just add these new directives at the bottom of the file, and set the DocumentRoot for localhost to C:/xampp/htdocs):
You would need to use xampp instead of local host to connect to the splash page, but you are only going to go to the xampp page when you administrate the site so it is really no different than using localhost.
You would then need to format you host like:
# For example:
#
#102.54.94.97 rhino.acme.com # source server
#38.25.63.10 x.acme.com # x client host
127.0.0.1 localhost
::1 localhost
127.0.0.1 localhost
127.0.0.1 yata4
127.0.0.1 xampp
I think I finally beat the SOB. Moved the xampp folder from under the document root (htdocs) to c:\vhosts and added the corresponding entries
<VirtualHost *:80>
DocumentRoot c:/vhosts/xampp
ServerName xamppoff
</VirtualHost>
and 127.0.0.1 xamppoff to the HOSTS, and now it works. Multiple virtual hosts are also placed there, and they work too, so I guess that’s it.
When you enable virtual hosting, Apache disables the main server root
I think it was due to the part in bold which applies to Apache 2.0. While I tried to place the folders for the virtual hosts inside the htdocs folder (which is how I used to do it when I was running the multiple virtual hosts setup under Apache 1.3), they didn’t work as this version uses Apache 2.0. Now that I moved them away from under htdocs, everything seems to work OK. Fingers crossed. Maybe now I can finally get to work instead of fighting the server.