I am running Apache/PHP on MacOS X Lion 10.7.4. My directory structure is set up as so:
/Users/achan/Sites/
lrwxrwx--- 1 achan staff 23B Apr 27 16:21 epwbst@ -> /Users/achan/dev/epwbst`
where epwbst/
is a symlink inside of ~/Sites
.
If I put test.php
inside of the Sites/
directory, Apache serves up the file correctly; it spews out phpinfo()
like it is supposed to. If I put the same file under the symlink, I get this error:
[Mon May 28 14:47:13 2012] [error] [client ::1] PHP Warning: Unknown: failed to open stream: No such file or directory in Unknown on line 0
[Mon May 28 14:47:13 2012] [error] [client ::1] PHP Fatal error: Unknown: Failed opening required '/Users/achan/Sites/epwbst/test.php' (include_path='.:/usr/lib/php/pear') in Unknown on line 0
Just to be sure that Apache was working, I created a test html file under ~/Sites/epwbst/
and Apache served it up as expected.
Why can't Apache run php under my symlinked directory?
I've pasted my php config here: http://pastebin.com/gg27JyVZ
Okay, this drove me nuts for hours. It is a permissions issue, but not how one might think. The problem rests with the permissions of the symbolic link itself:
Here's the rub:
chmod
won't normally change the permissions on symbolic links, because (with the apparent exception ofphp5_module
and some other cases beyond the scope of this answer) those permissions are largely irrelevant as they are ignored in nearly all contexts. Here's the fix:Note the
-h
. From the man page:For some reason,
php5_module
actually pays attention to the permissions on the symbolic link. If they are too restrictive,php5_module
will refuse to see the target, even if thehttpd
user could otherwise read and run that very same target using/usr/bin/php
.Consider the following:
So far, so good. Now consider:
Hmmm. My
httpd
runs as user_www
, so let's check to see if that user can read.../foo/info.php
:Yup. Now let's see if that user can run
.../foo/info.php
:Yes?! WTF?! Grrr! Now repair it:
Bang. Done.
So, yes. It appears that
php5_module
does something paranoid and nonstandard. This may have gone overlooked asumask
often defaults to022
, which will at least create symbolic links with755
. Also, many filesystems (not HFS+) impose at the kernel level permissions of 777 during symbolic link creation, irrespective ofumask
.You and I appear to be the two people in the solar system running Apache+PHP on HFS+ while setting our umask to something more restrictive than the default. I'll bet you even use case-sensitive HFS+, too. ;o)