Apache Apache Web Server

My local development environment was created by downloading and executing the WampServer 2.2e file (wampserver2.2e-php5.4.3-httpd2.2.22-mysql5.5.24-32b.exe) from wampserver.com. This included the following 32-bit program versions:

Open Permissions to Localhost
After the servers are installed and started, the Localhost menu option will test access to the local host (http://localhost/). If the browser returns a 403 - Forbidden error, you need to modify the Apache configuration file (httpd.conf) to allow permission:
  1. httpd.conf
    1. Location: C:\wamp\bin\apache\apache2.2.22\conf\httpd.conf
    2. After making a backup copy of the original file, change the "Deny from all" to "Allow from all" in the following code segment:

      From:
      #   onlineoffline tag - don't remove
          Order Deny,Allow
          Deny from all
          Allow from 127.0.0.1
          _____________________
      To:
      #   onlineoffline tag - don't remove
          Order Deny,Allow
          Allow from all
          Allow from 127.0.0.1
                
    3. Restart the servers and try the Localhost option again. The Server Configuration page should display in the browser. Use the link to phpinfo() on this page to verify the PHP environment is working.
  2. hosts
    1. Location: C:\Windows\System32\drivers\etc\hosts
    2. Make a backup copy of the "hosts" file.
    3. Make sure the first line in the hosts file contains the following (without quotes): "127.0.0.1  localhost"

Setting Up a Virtual Host

The default setup for a web server allows you to create only one website. To create additional websites, such as for testing websites, you can create a Virtual Host for each additional website. This is also how hosting companies managed shared hosting. It provides for a unique local domain for each website. My website is kcshadow.net, so I used just kcshadow as my test domain name. This allows you to add or remove the .net in the address bar of the web browser to switch between the live and testing sites.

Creating virtual hosts consist of two steps:

  1. Edit hosts file.
  2. Register virtual host with web server.

Modify the following configuration files to set up a virtual host. Files are case-sensative, pay attention to detail.

  1. hosts
    1. Location: C:\Windows\System32\drivers\etc\hosts
    2. Make a backup copy of the hosts file.
    3. The first line in the host file must be: 127.0.0.1  localhost
    4. On the second line, add the following line (without quotes): "127.0.0.1 kcshadow" where kcshadow is the domain name for your virtual host.
    5. If this line exists:
      ::1  localhost

      comment out the line with a #:
      #::1  localhost
      as this line can prevent virtual hosts from working properly.
  2. httpd.conf
    1. Location: C:\wamp\bin\apache\apache2.2.22\conf\httpd.conf
    2. Make a backup copy of the httpd.conf file.
    3. Uncomment this line in httpd.conf: "Include conf/extra/httpd-vhosts.conf".
  3. httpd-vhosts.conf
    1. Location: C:\wamp\bin\apache\apache2.2.22\conf\extra\httpd-vhosts.conf
    2. Make a backup copy of httpd-vhosts.conf.
    3. This file contains examples of how to define virtual hosts. Delete or comment out the examples!
    4. Make sure the following line is active (not commented out):
      NameVirtualHost *:80
    5. At the bottom of the file add directory entry (permissions) for virtual host (use forward slash in path name):
                      
      <Directory "c:/www/kcshadow"> 
         Options Indexes FollowSymLinks
      AllowOverride All
      Order allow,deny
      Allow from All </Directory>
    6. Add the following local host entry at the bottom of the file:
                
      <VirtualHost *:80>
          DocumentRoot "c:/wamp/www"
          ServerName localhost
      </VirtualHost>
      
      
    7. Add the following virtual host entry at the bottom of the file:
                
      <VirtualHost *:80>
          DocumentRoot "c:/www/kcshadow"
          ServerName kcshadow
      </VirtualHost>
      

To test the syntax of the virtual host, enter the command: httpd -S location (c:/wamp/bin/apache/apache2.2.22/bin/). The results should indicate both the local host and the new virtual host exists as shown below:

VirtualHost configuration:

wildcard NameVirtualHosts and _default_ servers:
*:80 is a NameVirtualHost
default server localhost (C:/wamp/bin/apache/apache2.2.22/conf/extra/httpd-vhosts.conf:50)
port 80 namevhost localhost (C:/wamp/bin/apache/apache2.2.22/conf/extra/httpd-vhosts.conf:50)
port 80 namevhost kcshadow (C:/wamp/bin/apache/apache2.2.22/conf/extra/httpd-vhosts.conf:55)
Syntax OK

To test the functioning of the virtual host, restart servers. Then create a file called "test.php" in the root directory of the virtual host. Put this contents in the file:

<?php

   phpinfo();

?>

Then in a browser, go to http://kcshadow/test.php. This should display information about the current PHP installation as shown below:




Note: If you do not have permissions to the server configuration files, you may need to use the .htaccess (HyperText Access) file. This file is read on every HTTP request, so changes are immediate. The file was designed to provide directory level control for web server. In general, this file should only be used when you do not have access to the main server configuration file.

Note: To configure PHP, check the location of the "Loaded Configuration File" from the PHP (phpinfo) installation page to be sure you are modifying the correct version of the file. My PHP configuration file is located at C:\wamp\bin\apache\apache2.2.22\bin\php.ini. See the PHP webpage for instructions on configuring the php.ini file.


Remote Host Apache on Remote Host


Top