Home » Php » php – 403 Forbidden on symlink in web root

php – 403 Forbidden on symlink in web root

Posted by: admin July 12, 2020 Leave a comment

Questions:

I am on a shared hosting package on a LAMP stack with no shell access.

I can create symlinks using PHP’s symlink() function.

Let’s say my web root is /home/www/user1/public

Let’s say I have a real directory named /home/www/user1/public/real_dir

And I create a symlink named /home/www/user1/public/fake_dir pointing to real_dir

Why would I get a 403 Forbidden when trying to access www.mydomain.com/fake_dir but not when trying to access www.mydomain.com/real_dir?

It shouldn’t be a rights problem because when I create a file in PHP, I can access that all right.

I tried switching FollowSymlinks off and on in .htaccess (it was on), but no luck.

Could it be that FollowSymlinks is defined as not overwritable in a .htaccess file? Or is there something else to be aware of when working with Symlinks in Apache?

How to&Answers:

Apache has to be configured to allow access to the directory on the filesystem. This has to be done by a system administrator by inserting a <Directory> directive in the apache configuration files (httpd.conf).

Since the real directory is inside the web root it must be accessible, but FollowSymLinks may not have been enabled for the directory – this also has to be added to the <Directory> directive.

See http://httpd.apache.org/docs/2.0/mod/core.html#directory

Answer:

This is possible SELinux security issue.

cat /selinux/enforce
if the value is 1, set it to 0, then restart apache.