MultipleVirtual

How to setup multiple virtual hosts on local Apache server?

In this post, we will see how to setup multiple virtual hosts on a local Apache server and this will make development work more user-friendly!

Steps:

1. Updating .hosts file

2. Updating httpd.conf

3. Updating http-vhosts.conf

4. Restarting Apache and check the virtual server

Let’s consider that we have two projects (3sdev and bookdev ) available in the web root folder (..\wamp\www\).

1. Updating .hosts file

Open Notepad as administrator and then open host file to add 3sdev and bookdev project path there. Browse C:/Windows/system32/drivers/etc path and open hosts file. Add following lines there-

127.0.0.1  3s.dev

127.0.0.1  book.dev

Save the file and close the Notepad editor.

2. Updating httpd.conf

Go to Apache conf folder inside bin directory i.e. C:\wamp\bin\apache\apache2.4.9\conf and then open httpd.conf file. Comment httpd-vhosts.conf line like following-

# Virtual hosts
Include conf/extra/httpd-vhosts.conf

Save and close the file.

3. Updating http-vhosts.conf

Go to extra directory i.e. C:\wamp\bin\apache\apache2.4.9\conf\extra and then open httpd-vhosts.conf. Make changes like following-

<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot “C:/wamp/www”
ServerName localhost
ErrorLog “logs/localhost-error.log”
CustomLog “logs/localhost-access.log” common
</VirtualHost>
<VirtualHost *:80>
DocumentRoot “c:/wamp/www/3sdev”
ServerName 3s.dev
<directory “c:/wamp/www/3sdev”>
Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot “c:/wamp/www/bookdev”
ServerName book.dev
<directory “c:/wamp/www/bookdev”>
Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</directory>
</VirtualHost>

Save and close the file.

4. Restarting Apache and check the virtual server

Now restart the Apache server and then check the newly created host on the browser.

Write 3s.dev on browser and press enter. It will display 3sdev project page also please follow same also for book.dev.

So, now you can able to add more virtual hosts based on your need.

Leave a Reply

Your email address will not be published.