TAAT Technologie Cyfrowe

Virutal host manager

When you create a lot of virtual hosts on Windows, you are probably tried of updating httpd.conf, then hosts file, restarting apache and refreshing DNS cache. And the same once more when you remove virtual host.

To simplify that process, I wrote vhost.bat - a batch script for managing virtual hosts on Windows.

Virtual host manager usage

vhost show - to see all virtual hosts created by vhost.bat

vhost create yourdomain.dev - to create virtual host http://yourdomain.dev in the current directory.

vhost create yourdomain.dev c:\path\to\site\root\ - to create virtual host in specified directory.

vhost drop yourdomain.dev - to delete virtual host yourdomain.dev

vhost.bat installation

  1. Download and unzip archive.
  2. Copy all files to one of the directories listed in the PATH environment variable. Hit: path [Enter] in Windows console (Win+R) to determine the PATH. Alternatively you may create new folder for those files, and add it to the PATH in system properies.
  3. Edit vhost.bat CONFIGURATION and ensure all paths are OK.
    SET PATH_ARCHIVE="c:\users\user\www\+archive"
    SET PATH_APACHE_STOP="c:\program files\apache\bin\httpd.exe" -k stop
    SET PATH_APACHE_START="c:\program files\apache\bin\httpd.exe" -k restart
    SET PATH_APACHE_CONFIG="c:\program files\Apache\conf\httpd.conf"
    SET PATH_HOSTS="C:\Windows\System32\drivers\etc\hosts"
  4. To test, run Windows console (Win+R) and type vhost show


Post scriptum

I've included also newproject.bat script in the archive, which creates new Zend Framewok project (using zf.bat), and automatically creates virtual host. Note that zf.bat must be in the same directory.


newproject test.dev - creates directory test.dev in current directory, then new Zend Framework project there, changes current directory to project's public, and creates virtual host named test.dev pointing to public..