Categories
Apache Virtual Directory

Setting Up Virtual Directory In Apache 2.2

In order to allow web access to a different directory outside the root directory, you need to give Apache access to the directory, and then use the Alias directive. The Alias directive will map any directory into the web root.

For example if you want to create a virtual directory called test, and the directory is in the D:/example/test, then modify your httpd.conf and add the following entry at the bottom of the file:

<Directory "D:/example/test/">
    Options Indexes
    AllowOverride all
    Order Allow,Deny
    Allow from all
</Directory>

Alias /test D:/example/test

On a typical Windows installation, the httpd.conf file is usually located in the following directory:

C:\Program Files\Apache Software Foundation\Apache2.2\conf\httpd.conf

So if a file file.htm exists in D:/example/test,  the URL of the resource is:

http://www.example.com/test/file.html

and it will be served from:

D:/example/test/file.html

For more information visit the Apache HTTP Server Version 2.2 documentation.

Categories
Apache PHP

Configuring PHP in Apache

To enable PHP in Apache you need to do the following.

You need to tell PHP the root directory of Apache ie. In PHP.INI change the doc_root variable so that it holds the root directory of Apache:

Change PHP.INI (Usually located in [DRIVE]:\PHP\) entry for doc_root:

doc_root = "C:\Program Files\Apache Software Foundation\Apache2.2\htdocs"

Add the following lines in HTTPD.CONF (Usually located in [DRIVE]:\Program Files\Apache Software Foundation\Apache2.2\conf\):

ScriptAlias /php/ "C:/Program Files/PHP/"
AddType application/x-httpd-php .php .php5
Action application/x-httpd-php "/php/php-cgi.exe"
SetEnv PHPRC "C:/Program Files/PHP"

DirectoryIndex index.html index.php

Remove deny all from the following entry in HTTPD.CONF:

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
</Directory>

So that the new entry looks similar to:

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
</Directory>

That’s it… Happy coding!