How to configure Virtual Hosting on AppServ

With this tutorial, we are going to take a look at the best way to configure a local web server to serve fake domain/subdomains (or virtual hosts) accessible via our browser of choice. Using virtual hosts is a really useful solution to isolate configurations for each virtual host–and it’s easier to migrate code.

We are using Windows 7 as our OS and AppServ v2.5.10

Step 1: Enable the vhost_alias_module in our Apache configuration file:

Open file httpd.conf file located in D:\AppServ\Apache2.2\conf ( or C:\AppServ\Apache2.2\conf)

Change line 203:
#LoadModule vhost_alias_module modules/

To this:
LoadModule vhost_alias_module modules/

In the same file, we change line 561:
#Include conf/extra/httpd-vhosts.conf

To this:
Include conf/extra/httpd-vhosts.conf

Save the changes and close the file.

Step 2: Edit the vhosts configuration file (httpd-vhosts.conf) in order to define our virtual hosts:

We open the file (located in D:\AppServ\Apache2.2\conf\extra or C:\AppServ\Apache2.2\conf\extra)

Change line 27-34:

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.x
    DocumentRoot "C:/Apache2.2/docs/dummy-host.x"
    ServerName dummy-host.x
    ServerAlias www.dummy-host.x
    ErrorLog "logs/dummy-host.x-error.log"
    CustomLog "logs/dummy-host.x-access.log" common

To this:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot "D:/AppServ/www"
    ServerName localhost
    ServerAlias localhost
    ErrorLog "logs/localhost-error.log"
    CustomLog "logs/localhost-access.log" common

Now our localhost vhost is setup. Next, we will setup a custom vhost for our webapp project. To do this, let’s create a new folder called ex: “s3” in D:\AppServ\www . We can create some file in that folder like index.php.
Ex: we need create virtual host “s3.localhost”:

In the same file, we change lines 36-42

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host2.x
    DocumentRoot "C:/Apache2.2/docs/dummy-host2.x"
    ServerName dummy-host2.x
    ErrorLog "logs/dummy-host2.x-error.log"
    CustomLog "logs/dummy-host2.x-access.log" common

To this:

<VirtualHost *:80>
    ServerAdmin webmaster@s3.localhost
    DocumentRoot "D:/AppServ/www/s3"
    ServerName s3.localhost
    ErrorLog "logs/s3-error.log"
    CustomLog "logs/s3-access.log" common

Now, we save the changes and close the file.

Step 3: Open file C:\Windows\System32\drives\etc\hosts

We add 2 lines to the end of file: localhost s3.localhost

Step 4: restart your machine.

Now, open our browser and go to our newly created virtual host “s3.localhost”

Leave a Reply