Apache | Symbolic link not allowed or link target not accessible



Recently i needed to add a Symbolic link That Links to a External Directory to my Document Root, avoid copying work files from the external storage to the Document Root.

So i made the link using (ln -s) and configured the apache2.conf settings to allow Symbolic Links and restarted Apache with all configurations OK, bur when i browse the local server on 127.0.0.1, i cant see the linked server and when i try to access it ( 127.0.0.1/target/ ) it gives a Permission Problem?

After a long search i found out that all the configurations is Correct and the problem is pure Permission Problem after looking into the log file it says "Symbolic link not allowed or link target not accessible".

The Problem: Apache needs Permission to not only the folder in which is linked, instead it needs permission to all the way through until reaching it, so for example if you have your linked folder source in (USB/WORKS/PROJECTS/PROJECT_01), you need to set the permission of all these folders so that the user that runs Apache (for example [www-data]) have at least access permission...

The Solution:
1- Determine which user apache is using to run under by executing the following command:
cat /etc/apache2/envvars | grep USER

2- Once you know the user, which is by default "www-data", Change the Permession of the Root Folder of the Link Location. If you link /var/www/project01 > /media/USB1/works/projects/project1, then your Root of the linked folder is /media/USB1, so you will need to change the ownership and permission as follow:

check the folder group and add www-data to that group OR simply execute the following comand:
sudo chown www-data:www-data /media/USB1 -R

THEN
sudo chmod 755 /media/USB1

DONE! Now you can reload your apache server and you can access all the files.... ENJOY (:


Comments

Popular Posts