RSS
 

XAMMP and Virtual Hosts

29 Nov

Ok here are some docs on how to do virtual hosts. I do this allot on Unix machines, but found that windows has a little different setup.
I have learned that in the httpd.conf file you need to look for /conf/extra/httpd-xampp.conf. This is the start of the extra config files that you can include in apache. What i would recommend is that you create a new directory under extra called sites or enabled_sites. Then add a new line to the httpd.conf file as such.
Include conf/extra/sites/*.conf


After saving the file make or change into the extra/sites directory. We are going to make a new config file naming it dev1.conf. You can change the name to something that will work for you, i however will use the dev1 name in this post.

The dev1 file should contain the following code more config options can be added, but what is posted will get you started.

Note: You will need to change the DocumentRoot before you restart Apache
Note2: Also wrap your Document Root path in double quotes and don't include a trailing slash.

<VirtualHost *:80>
ServerName dev1.edmann.com
DocumentRoot "C:\Documents and Settings\ed_mann\workspace\dev1"
ErrorLog logs/dev1-error.log
CustomLog logs/dev1-access.log common
<Directory />
Order deny,allow
Deny from none
</Directory>
</VirtualHost>

Edit the httpd-vhosts.conf file in the extra directory and uncomment the NameVirtualHost *:80 line.
I like to keep my logs for each project separate. This helps trouble shoot problems... At least for me it does.
Now you need to edit your etc/hosts file. Windows has one and it is found in the following directory.


C:\WINDOWS\system32\drivers\etc

We need to add a new host for our dev1 Virtual host. Something like the following will work: 127.0.0.1 dev1.mysite.com
or just 127.0.0.1 dev1
Create a index.php file in the directory of you new dev1 site. You can put the following content. <? php phpinfo(); ?>
Now start or restart apache and try to go to the dev1 website. You can just type in dev1 and it should take you to the index page and display the php info.
Let me know if you have any problems. Once you have one dev project working, just copy the dev1.conf file to dev2.conf change the path and restart apache. Edit your hosts file, and you should be good to go.

Leave a Reply

Comments are closed