Today's Question:  What does your personal desk look like?        GIVE A SHOUT

Host multiple websites in Wamp

  infinite designs        2011-04-04 11:42:06       9,376        0    

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. WAMPLAMP (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”.Wamp Menu

So now that WAMP is installed you can browse to http://localhost and look at your WAMP dashboard.
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-domainYou 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.
Hosts File

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.confand uncomment it. Your file should now look like the picture below. Save it and close your text editor.
httpd.conf file

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 module is needed to preserve the http://localhost. This way we always have our dashboard. The second (and potentially more) are for each subdomain you choose. I also added the to the second virtual hosts because this allows my folder to be located in C:\User…. If you completely removed thebranches, then you would get a 403 forbidden error, stating apache doesn’t have permission to execute inside that folder. HOWEVER, if you chose your DocumentRoot to be in lets say C:\wamp\www\your-local-domain, then you could omit the whole <directory>. It’s up to you.
httpd-vhosts.conf file

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!


Source : http://www.infinitedesigns.org/archives/217

MULTIPLE HOSTS  WAMP  WEBSITES  DIFFEREN 

Share on Facebook  Share on Twitter  Share on Weibo  Share on Reddit 

  RELATED


  0 COMMENT


No comment for this article.