Confused already? Of course, I’ll try to explain, so suggest a better title if you wish. If you’re using WAMP server on MS Windows (perhaps this would be even simpler to do on Linux) like I do, sometimes you add new applications to new folders in your default root folder of your WAMP server, for example:
- c:wampwwwapp1
- c:wampwwwsite2
which are respectively accessible from the follwing URLs:
- http://localhost/app1/
- http://localhost/site2/
Sometimes you will need to run an application in your root folder (http://localhost/). Sometimes you will need to run multiple applications or websites in your WAMP root folder, and since you can’t run multiple websites in your root at the same time, what would be the easiest way to switch between rooted applications?
You can do this:
- create a set of batch scripts which would make switching websites in WAMP root fast and easy
- and an added bonus you can even modify your hosts (c:WINDOWSsystem32driversetchosts) file to have the www.mylatestsite.com requests redirect to localhost
Main advantage of these two things is that you can develop the website locally and just deploy it to the live server without any patching for absolute URLs to your local server.
The localhost
First we need to create the script for restoring the original state of the WAMP server, so here’s what I did for the original localhost settings:
- create folder to place your Apache configuration files and batch scripts, for example c:wamp.server-switch
- create a sub-folder configs, here you will store httpd.config files for WAMP Apache configuration for different root applications
- copy the original c:wampbinapacheApache2.2.11confhttpd.conf to c:wamp.server-switchconfigslocalhost.httpd.conf
- create a script named localhost.bat and place it in c:wamp.server-switch folder
- edit the script to:
copy configslocalhost.httpd.conf ..binapacheApache2.2.11confhttpd.conf /Y
net stop wampapache
net start wampapache
With this, you will create a script which will restore default Apache httpd.conf file and restart the server.
The www.mylatestsite.com
Next we need to create the script for switching a “www.mylatestsite.com” to run as a root application on your localhost webserver:
- we already have the .server-switch folder with required subfolders and files from the “The localhost” section
- copy the original c:wampbinapacheApache2.2.11confhttpd.conf to c:wamp.server-switchconfigswww.mylatestsite.com.httpd.conf
- create a script named www.mylatestsite.com.bat and place it in c:wamp.server-switch folder
- edit the script to:
copy configswww.mylatestsite.com.httpd.conf ..binapacheApache2.2.11confhttpd.conf /Y
net stop wampapache
net start wampapache - now we need to create the root folder for the www.mylatestsite.com site, you can do it here c:wamp, so the target folder for your application/website files will be c:wampwww.mylatestsite.com
- place your application/site files to c:wampwww.mylatestsite.com
- edit the c:wamp.server-switchconfigswww.mylatestsite.com.httpd.conf, find the DocumentRoot parameter and modify it to match this:
DocumentRoot “c:/wamp/www.mylatestsite.com/”
With this, you will create a script which will configure the Apache httpd.conf for theĀ www.mylatestsite.com configuration and restart the server. It will modify the WAMP server configuration so the root of your server will match the root of your target application/site. This is reversible to the default WAMP settings, just by running the batch script described in the “The localhost” section.
NOTE: I’m using WAMP Server 2.0 with Apache 2.2.11, a different version of Apache server or WAMP Server might have different folder names.