Sections:

Configuring Virtual Hosts in Apache 2.4

Allows you to map local domain(s) to specific directories.

Enable

  1. Click search.
  2. Type Command Prompt
  3. Press enter.
  4. In the command prompt window, type notepad C:\Apache24\conf\httpd.conf
  5. Press Enter
  6. In the nodepad window, search for the phrase vhosts
  7. Change #Include conf/extra/httpd-vhosts.conf

    to

    Include conf/extra/httpd-vhosts.conf
  8. Click File. Click Save.
  9. Click File. Click Exit.

Configure

  1. In the command prompt window, type notepad C:\Apache24\conf\extra\httpd-vhosts.conf
  2. Press Enter
  3. Locate the section that reads:

    <VirtualHost *:80>
        ServerAdmin webmaster@dummy-host.example.com
        DocumentRoot "${SRVROOT}/docs/dummy-host.example.com"
        ServerName dummy-host.example.com
        ServerAlias www.dummy-host.example.com
        ErrorLog "logs/dummy-host.example.com-error.log"
        CustomLog "logs/dummy-host.example.com-access.log" common
    </VirtualHost>
  4. Set the value of DocumentRoot to the directory where you want to serve the files from. As an example, if your files are located in C:\var\www\mysite1. Change

    DocumentRoot "${SRVROOT}/docs/dummy-host.example.com"

    to

    DocumentRoot "C:/var/www/mysite1"
  5. Change the value of ServerName to the domain where you want to use in the web address bar. To use http://mysite1.localhost, change

    ServerName dummy-host.example.com

    to

    ServerName mysite1.localhost
  6. Adjust the logging directories to match the name of the website. Change

    ErrorLog "logs/dummy-host.example.com-error.log"
    CustomLog "logs/dummy-host.example.com-access.log" common

    to

    ErrorLog "logs/mysite1.localhost-error.log"
    CustomLog "logs/mysite1.localhost-access.log" common
  7. Give the web server permission to read the directory.

    <Directory "C:/var/www/mysite1">
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
    </Directory>
  8. Click File. Click Save.

Restart Apache

  1. Click search
  2. Type services.msc
  3. Press Enter
  4. Right click on Apache2.4
  5. Click Restart