Wednesday, April 22, 2009

Apache - Making Localhost and Virtual Hosts (vhosts) Work Together

I’ve been searching for this for quite sometimes almost forget about it.  Anyway, I’ve found the solution here to share…

If you have a situation that you want to round your live site from your machine, you can always change the hosts file and your conf file.  Example, you want to make local version accessible

Add setting in your Apache Configuration file (httpd.conf), for me I prefer to add in a new file so that it will not mixed up

# Virtual hosts
#Include conf/extra/httpd-vhosts.conf

Include conf/extra/mysite-vhosts.conf


In mysite-vhost.conf, you have to set

<VirtualHost *:80>
DocumentRoot "C:/Apache/htdocs/"
    ErrorLog "logs/"
    CustomLog "logs/" common


Pre-create the log file if Apache prompt you error when restarting.

Next, change your hosts file to (your hosts file located in [Windows] C:/windows/system32/drivers/etc/hosts)

Do this: (you can access via or       localhost


If you restarted your apache right now and have other file that located in your htdocs folder, these site will not be accessible, for example your http://localhost/test will not work.  The solution:

<VirtualHost _default_:80>
    DocumentRoot C:/Apache/htdocs

Restart your apache and DONE!

Enjoy coding!!!

No comments: