Creating a virtualhost in Windows environment is a lot of hassle. You have to create the site folder, edit httpd.conf, hosts and whatnow. In order to automate some of that I decided to try and create a batch file to automate some of that. Here what I came up with for starters:
@ECHO OFF ::location of vhosts SET BASEURL=D:\web\vhosts\ :sitenameprompt ::ask for a sitename set /p sitename="Enter Sitename: " %=% echo Before IF IF EXIST %BASEURL%%sitename% echo The specified site folder already exists! Choose another. IF EXIST %BASEURL%%sitename% goto sitenameprompt IF NOT EXIST %BASEURL%%sitename% echo Creating folder IF NOT EXIST %BASEURL%%sitename% MD %BASEURL%%sitename% echo Adding virtualhost to httpd.conf pause ( echo ###%sitename%### echo <VirtualHost *:80> echo ServerAdmin admin@%sitename% echo DocumentRoot "%BASEURL%%sitename%" echo ServerName %sitename%.dev echo ServerAlias %sitename%.dev echo <Directory "%BASEURL%%sitename%"> echo Options Indexes FollowSymLinks Includes ExecCGI echo Order allow,deny echo Allow from all echo </Directory> echo </VirtualHost> ) >>D:\web\xampp\apache\conf\extra\httpd-vhosts.conf pause echo Restarting apache ::httpd -k restart
Now when running this script it gives a syntax error at the httpd.conf part. Bear in mind I am rather new at this so its propably something obvious. So where did I screw up?