Blog Pro de Jean-Baptiste HEREN

Notes d'un consultant Freelance en Informatique

To content | To menu | To search

Configure Virtual Hosts in WAMP Server (MS Windows)

image_menu_wamp.gifWAMP is a standalone LAMP(Linux Apache Mysql Php) installation package for windows. It is very usefull when you want to try or develop something fast on your local machine.

In the following example, WAMP is located on d:\wamp. This is not really important here, but I have four different hosts installed :

  • sf.localhost : symfony project
  • mag.localhost : Magento Installation
  • a.localhost : Apostrophe CMS installation
  • localhost : the default WAMP home page

1- Edit the httpd.conf

Uncomment the following line to inclute the httpd-vhosts.conf file.

[script]
# Virtual hosts
Include conf/extra/httpd-vhosts.conf

2- Define your virtual hosts with the httpd-vhosts.conf The file is located in wamp\bin\apache\Apache2.2.11\conf\extra. Here is an example defining 3 virtualhosts plus the default localhost

[script]
#
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at 
# <URL:http://httpd.apache.org/docs/2.2/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# Use name-based virtual hosting.
#
NameVirtualHost *:80

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#

# Magento
<VirtualHost *:80>
    ServerAdmin webmaster@mag.localhost
    DocumentRoot "D:\wamp\www\magento"
    ServerName mag.localhost
    ErrorLog "logs/mag.localhost-error.log"
    CustomLog "logs/mag.localhost-access.log" common
    <Directory "D:\wamp\www\magento">
        Options Indexes FollowSymLinks
        AllowOverride all
        Order Deny,Allow
        Deny from all
        Allow from 127.0.0.1
    </Directory>
</VirtualHost>

# localhost
<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot "d:\wamp\www"
    ServerName localhost
    ErrorLog "logs/localhost-error.log"
    CustomLog "logs/localhost-access.log" common
    <Directory "d:\wamp\www">
        Options Indexes FollowSymLinks
        AllowOverride all
        Order Deny,Allow
        Deny from all
        Allow from 127.0.0.1
    </Directory>
</VirtualHost>

# Symfony
<VirtualHost *:80>
    ServerAdmin webmaster@sf.localhost
    DocumentRoot "d:/wamp/www/sf_sandbox/web/"
    ServerName sf.localhost
    ServerAlias www.sf.localhost
    ErrorLog "logs/sf.localhost-error.log"
    CustomLog "logs/dummy-host.localhost-access.log" common
    <Directory "d:/wamp/www/sf_sandbox/web/">
        Options Indexes FollowSymLinks
        AllowOverride all
        Order Deny,Allow
        Deny from all
        Allow from 127.0.0.1
    </Directory>
    Alias /sf/ "d:\wamp\www\sf_sandbox\lib\vendor\symfony\data\web\sf/" 
    
    <Directory "d:\wamp\www\sf_sandbox\lib\vendor\symfony\data\web\sf/">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride all
            Order allow,deny
        Allow from all
    </Directory>    
</VirtualHost>

# Apostrophe Symfony
<VirtualHost *:80>
    ServerAdmin webmaster@a.localhost
    DocumentRoot "d:/wamp/www/asandbox/web/"
    ServerName a.localhost
    ServerAlias www.a.localhost
    ErrorLog "logs/sf.localhost-error.log"
    CustomLog "logs/dummy-host.localhost-access.log" common
    <Directory "d:/wamp/www/asandbox/web/">
        Options Indexes FollowSymLinks
        AllowOverride all
        Order Deny,Allow
        Deny from all
        Allow from 127.0.0.1
    </Directory>
    Alias /sf/ "d:\wamp\www\asandbox\lib\vendor\symfony\data\web\sf/" 
    
    <Directory "d:\wamp\www\asandbox\lib\vendor\symfony\data\web\sf/">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride all
            Order allow,deny
        Allow from all
    </Directory>    
</VirtualHost>

3- Add your virtual hosts to the local hosts.conf

Edit the file located in C:\WINDOWS\system32\drivers\etc\hosts, then add your virtual hosts.

[script]
127.0.0.1       localhost
127.0.0.1       sf.localhost
127.0.0.1       mag.localhost
127.0.0.1       a.localhost

4- Start Wamp & give a try

After you started wamp, you can now open your navigator an give a try to your dirrefent virtual hosts. Apache will recognize automatically the address you want to access, even if everything is hosted on the same machine.

Jean-Baptiste Heren

Author: Jean-Baptiste Heren

Stay in touch with the latest news and subscribe to the RSS Feed about this category

Comments are closed


no attachment



You Might Also Like

Configure Virtual Hosts in WAMP Server (MS Windows)

WAMP is a standalone LAMP(Linux Apache Mysql Php) installation package for windows. It is very usefull when you want to try or develop something fast on your local machine. In the following example,...

Continue reading

désactiver le timeout avec sfGUardSecurityUser dans Symfony

Voici comment désactiver le timeout des sessions Symony, utilisant une classe myUser dérivée de sfGuardSecurityUser. Modifier la durée maximale de session dans php.ini [ini] session.gc_maxlifetime =...

Continue reading