This is more of a reminder for me but this might also help somebody else.
I’ve had to set up virtual servers for apache on windows a couple of times (using php5.2.6 and apache 2.2 on XP and Vista) and can never quite remember exactly what it is that I have to put where, so here is my way of doing it:
- Open up the windows hosts file (for me found in windows\windows32\drivers\etc\)
- Under 127.0.0.1 localhost, add in the new virtual host and save eg.
127.0.0.1 newhost // set the name of your new virtual host
- Open up the apache httpd.conf file (found in your apache conf folder, for me its Program Files\Apache Software Foundation\Apache2.2\conf\)
- Underneath the line that specifies DocumentRoot, add in the following:
DocumentRoot "C:/web/local/publichtml" //specify localhost now that there will be multiple hosts
ServerName newhost // set to the name of your new virtual host
DocumentRoot "C:/web/test/publichtml" // specify the document root of your new virtual host
- Also add in a new entry below the existing localhost <Directory
"C:/web/local/publichtml"> section, so that you can configure the document root of your new virtual host seperately. So add in the following:
<Directory "C:/web/test/public"> //set to the document rootof your new virtual host
Options Indexes FollowSymLinks
Allow from all
- Restart your apache server
You should now be able to go to newhost in your browser and see whatever files that you have in there. (If not, check your spellings and document roots, restart apache, and failing that, google it!).
There are other ways of doing this, but for my needs this was the simplest and most effective way of setting up virtual hosts.