-
-
Save jasondavis/a6fbd217ac2a9d7b9a32af086ea7a1b9 to your computer and use it in GitHub Desktop.
Windows batch script for creating new virtual host entries on Apache.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
set texteditor=subl rem Text editor of your choice e.g. Sublime Text (subl) | |
set hostsfile=C:/Windows/System32/drivers/etc/hosts rem Where Windows' hosts file is located | |
set vhostsfile=C:/wamp/bin/apache/apache2.4.9/conf/extra/httpd-vhosts.conf rem This one depends on your installation. | |
set htdocs=C:/wamp/www rem This one depends on your installation. | |
if ["%1"] == ["edit"] goto:edit | |
if ["%1"] == ["add"] goto:add | |
goto:usage | |
:add | |
if ["%2"] == [""] echo Insufficient parameter :-( & goto:usage | |
echo.127.0.0.1 %2 >> %hostsfile% | |
echo.^<VirtualHost *:80^> >> %vhostsfile% | |
echo. ServerName %2 >> %vhostsfile% | |
echo. ServerAlias %2 >> %vhostsfile% | |
echo. DocumentRoot "%htdocs%/%2/" >> %vhostsfile% | |
echo. ^<Directory "%htdocs%/%2/"^> >> %vhostsfile% | |
echo. Options Indexes FollowSymLinks >> %vhostsfile% | |
echo. AllowOverride All >> %vhostsfile% | |
echo. Order allow,deny >> %vhostsfile% | |
echo. Allow from all >> %vhostsfile% | |
echo. ^</Directory^> >> %vhostsfile% | |
echo.^</VirtualHost^> >> %vhostsfile% | |
echo. >> %vhostsfile% | |
echo.%2 added :) | |
goto:eof | |
:edit | |
if ["%2"] == [""] echo Insufficient parameter :-( & goto:usage | |
if ["%2"] == ["v"] echo Editing httpd-vhosts.conf & %texteditor% %vhostsfile% & goto:eof | |
if ["%2"] == ["h"] echo Editing hosts & %texteditor% %hostsfile% & goto:eof | |
goto:eof | |
:usage | |
echo.Usage: | |
echo. vhosts add yourvirtualhost.com | |
echo. vhosts edit v | |
echo. vhosts edit h |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment