How to create a virtual host on wamp server

Follow the below simple steps to create virtual hosts and solve the problems related to it:

STEP 1
Make your server listen to a new port in the httpd.conf file of wamp server
Listen 82
etc. Mention the port number which you want to assign.
STEP 2
Also, in the same httpd.conf file make a directory as follows :

<Directory "path">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.2/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride all

    #
    # Controls who can get stuff from this server.
    #

#   onlineoffline tag - don't remove
    Order Deny,Allow
    Deny from all
    Allow from 127.0.0.1

</Directory>

STEP 3
After the above steps are completed, then in httpd.conf file enable virtual host by un commenting the below line:

# Virtual hosts
# Include conf/extra/httpd-vhosts.conf [i.e remove “#” from this line ]

STEP 4
Now create a virtual host for the same path by going to C:\wamp\bin\apache\Apache2.2.21\conf\extra in the file httpd-vhosts.conf file as follows :

<VirtualHost *:82>
    
    DocumentRoot "path"
    ServerName localhost
     
    ErrorLog "logs/file.log"
    CustomLog "logs/file.log" common
</VirtualHost>

Now the application is ready to be hosted and can be run as localhost:82 on any browser.

But after you enable virtual host in httpd.conf file, the application hosted on your localhost will stop working and will show permissions error, so to continue with hosting your default application, you need to edit the httpd-vhosts.conf file and change the directory path and server name with your default application’s path and localhost respectively.
example: Mine default application was hosted on default port 80, so to continue hosting that file on localhost, I need to edit the httpd-vhosts.conf file’s port number 80 virtual host as follows:

<VirtualHost *:80>
    DocumentRoot "path"
    ServerName localhost
    ErrorLog "logs/testError.log"
    CustomLog "logs/testCustomError.log" common
</VirtualHost>

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>