Linking Directory Outside Web Root Directory Using Symbolic Link

If you run your own web server on your Linux or Unix based operating system, including Mac OS X, then sometimes you would like to share another directory which reside outside of your web root directory.

For a case example, when you have some data on a USB flash drive you wish to share on your web server, you may have to copy the contents to some folder on your web server root directory to make it accessible through the web. But, you may accomplish the same thing by just making a symbolic link (a shortcut path or directory) which reside on your document root of your web server to the mount point of your USB flash drive and set it’s permissions to be readable by your webserver process user.

Here an example, my web server document root is says on:


and I would like to share the contents of my USB flash drive to:


So, me or my friends are able to access the contents through the web browser by typing a simple URL like below:


I have mounted (automatically) my USB flash drive to:


That is my mount point, but yours may be different. Then open up your Terminal and go to your web server document root path. In my case I type:

cd /webdocs

and, create a symbolic link named flashdrive to /Volumes/Pendrive by the following ln command below:

ln -s /Volumes/Pendrive flashdrive

So that a “symbolic” folder named flashdrive are inside your webserver document root and pointing to the content of your USB flashdrive. Don’t forget to check the permissions of your USB flashdrive, you may have to alter the permission so that ‘other’ have read permission to make it readable. Altering permission of file or folder in Linux/Unix systems can be done by chmod command.

If you done it correctly, now you should be able to access your USB flash drive contents from web browser (easily).