sprunk
sprunk

Reputation: 33

PHP Symlink Permission Denied

I know this question is asked a lot, but I can't seem to find the error why my symlinks sometimes aren't working.

I have two folders:

/home/user/domains/example.com/folder1
/home/user/domains/example.com/folder2

These are their permissions:

drwx--x--x  9 root   root   4096 May 12 11:15 home
drwx--x--x  7 user   access 4096 Feb  9 10:23 user
drwx--x--x  3 user   user   4096 May  5  2014 domains
drwx--x--x 12 user   user   4096 Jul  7 09:52 example.com
drwxr-xr-x  2 apache apache 4096 Jan 21 09:22 folder1
drwxrwxrwx  4 user   user   4096 Jul  9 10:38 folder2

in PHP I create two symlinks:

symlink("/home/user/domains/example.com/folder1","whatever/folder");
symlink("/home/user/domains/example.com/folder2","whatever/folder");

Why is my symlink to folder1 working and my symlink to folder 2 not? I have been looking at it for hours now..

Edit: Well, as my provider isn't of any help, I'd like to try a different solution: create a symlink and immediately change its owner. This, however, gives me an 'Operation not permitted' error. Any ideas on that?

Upvotes: 2

Views: 17011

Answers (4)

Ja͢ck
Ja͢ck

Reputation: 173562

Assuming the symbolic links were created successfully, folder2 most likely yields a permission error when Apache is configured to only follow symbolic links if the owner matches; you're looking for this specific configuration option:

SymLinksIfOwnerMatch

You could make Apache less rigid by using the following option instead:

FollowSymLinks

Alternatively, fix the ownership of the symbolic link target to make it work.

Upvotes: 3

CheckeredMichael
CheckeredMichael

Reputation: 571

Change the user group of folder2 from user:user to apache:apache

chown -R apache:apache folder2

The reason is because Apache needs the group permissions rather than a normal user.

Upvotes: 0

Mahdyfo
Mahdyfo

Reputation: 1173

Does whatever/folder have enough permissions?

Remove folder1 and folder2 then Try

symlink("/home/user/domains/example.com/folder1.txt","whatever/folder");

Upvotes: 0

hh2000
hh2000

Reputation: 51

Try to delete both symlinks then 1) try PHP again and see if it persists and 2) logging in via SSH and create the same links using ln instead, for example

ln -s whatever/folder /home/user/domains/example.com/folder1

If that works, then it is probably a permission issue with the folder you are linking from or into, that the apache server / PHP cannot address

Upvotes: 0

Related Questions