Sunday, March 16, 2014

How to create directory alias in Apache httpd.conf


-----
How to create directory alias in Apache httpd.conf

INTRODUCTION

There are frequently circumstances where it is necessary to allow web access to parts of the filesystem that are not strictly underneath the DocumentRoot. Apache offers several different ways to accomplish this.
The Alias directive allows documents to be stored in the local filesystem other than under the DocumentRoot. URLs with a (%-decoded) path beginning with URL-path will be mapped to local files beginning with directory-path. The URL-path is case-sensitive, even on case-insensitive file systems.
The Alias directive will map any part of the filesystem into the web space. For example, with “Alias /docs /var/web” the URL http://www.example.com/docs/dir/file.html will be served from /var/web/dir/file.html.
This tutorial uses USBWebserver (USBW) as a starting point for a person to learn about Directory Alias. After that, the person would be able to apply that on XAMPP.

STEPS

2) Extract the folder 8.5 from the zip file “USBWebserver v8.5.zip”  as USBW into c:\. (Refer to screenshot below).
3) Go into the folder and run usbwebserver.exe. (Refer to screenshot below).
4) When the USBW Control Panel appears, click the button “phpmyadmin”. (Refer to screenshot above).
5) Observe the following:
5.2) Notice that the folder phpmyadmin doesn’t exist in web root folder.
5.3) Instead, the folder is outside of the web root folder.
6) The httpd.conf for USBWebserver is stored in C:\USBW\settings. (Take note that different Apache-MySQL-PHP Package have different location for configuration files).
7) Using Code Editor program, find the codes using keyword “Alias”. You should find the following:
### PHPMYADMIN ###
Alias /phpmyadmin "{path}/phpmyadmin/"
<Directory "{path}/phpmyadmin/">
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>
8) Define an alias for a new directory myaliasdir.
8.1) Create a new directory myaliasdir in USBW folder e.g. C:\USBW\myaliasdir
8.2) Create a new php script file index.php in myaliasdir directory.
<?php
echo "It Works!!!";
?>
8.3) Copy the codes in Step 7, paste into new lines in the same file (httpd.conf), and edit as follows:
### MyAliasDir ###
Alias /myaliasdir "{path}/myaliasdir/"
<Directory "{path}/myaliasdir/">
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>
8.4) Restart the Apache. (If there is no effect, close the USBW Control Panel and run again)
9) Refer tutorial http://secure-steps.blogspot.com/2014/03/how-apache-and-php-works.html. Can you apply the Step 8 to this XAMPP15 server? This time change the output to “It Works+++”.

REFERENCES:


No comments:

Post a Comment