I have decided to start playing around with the Zend Framework. I have a web host (of course) however sometimes when developing I find it is easier and faster to use a local web server, with all the bells and whistles. WAMP, LAMP (this link is ubuntu specific, but any linux distribution should have easy HowTo guide for installing the LAMP software stack), MAMP, all provide the basic environment for beginning web development, and some have nice little GUIs to help you configure and maintain your local web server.
So for this tutorial I am going to show you how to add multiple virtual hosts to a WAMP installation. I am using the latest version from their website at the time this article was written. I installed WAMP, and left all defaults when going through the install wizard. I then launched WAMP and a nice little “odometer†icon appears in the System Tray, and cycles through 3 phases. As is starts the services (MySQL, and Apache) it cycles through the phases, and when you only see white (with some black) then all services started successfully. The little Lock in the middle of the icon means that the webhost is in private mode, so if your on an internal network, this means only you can view the website, and not somebody else. But if you want another user to see your webpage (perhaps a co-worker on another computer), you can then simply Left Click the icon and choose“Put Onlineâ€.
So now that WAMP is installed you can browse to http://localhost and look at your WAMP dashboard.
This is great, and we can choose the option to put all of our projects or development sandboxes in the “Alias†part of apache, but then each address would be http://localhost/MYALIAS which is bland. We want to make our own local URLs link http://MyAlias, so we can host multiple projects locally each with unique domain names. So we have to get apache to do so. Follow the instructions below to accomplish this.
First lets edit the windows hosts file located in C:\Windows\system32\drivers\etc\hosts. Open up the file in your favourite text editor and add a line like127.0.0.1 your-local-domain
You can put any name in place of your-local-domain, just be sure to change it everywhere it is mentioned in this guide. Your file should look something like mine does in the picture below.
Now you can save that and close your text editor. Next we want to edit our httpd.conf file and httpd-vhosts.conf file. So first browse to C:\wamp\bin\apache\apache2.2.8\conf and open up httpd.conf in your favorite text editor. Then scroll down to the bottom. Look for this lineInclude conf/extra/httpd-vhosts.conf
and uncomment it. Your file should now look like the picture below. Save it and close your text editor.
Now guess what file we are going to edit next? The include file we just uncommented of course. So now browse just one more folder down the tree to C:\wamp\bin\apache\apache2.2.8\conf\extras and open the in your favourite text editor once again. Now scroll to the bottom and add this code<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot "c:/wamp/www"
ServerName localhost
ErrorLog "logs/localhost-error.log"
CustomLog "logs/localhost-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot "c:/Users/marf/Projects/your local folder/html"
ServerName your-local-domain
ErrorLog "logs/your_own-error.log"
CustomLog "logs/your_own-access.log" common
<directory "c:/Users/marf/Projects/your local folder/html">
Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</directory>
</VirtualHost>
Now let me explain. The first
Save the file and close your text editor. Now all that’s left is to restart apache, which can simply be done by left clicking the little wamp odometer, and clicking “restart all servicesâ€. Done, now you can go to http://your-local-domain and you will probably get a 404 page not found error, but throw an index.html in the folder and it should work like a charm.
Enjoy!