开发者

is_dir returning false on symlinks in apache

开发者 https://www.devze.com 2023-03-26 04:40 出处:网络
I run a third party PHP application on my local AMP stack on my Mac. I recently bought a new Mac Mini with Lion, and am trying to set it up. My previous computer was a MB air with MAMP. Now I\'m using

I run a third party PHP application on my local AMP stack on my Mac. I recently bought a new Mac Mini with Lion, and am trying to set it up. My previous computer was a MB air with MAMP. Now I'm using the built-in apache/php and a homebrew installed MySQL.

Here's my problem: I开发者_开发技巧 have a directory with symbolic links. These symlinks are to directories, and the PHP application is checking these with is_dir().

On my Lion AMP setup, this is_dir() is failing. The same setup on my Snow Leopard MAMP is_dir() works fine with my symlinks.

Here's where it gets more curious. If I do php -a (php interactive command line mode), and do is_dir() on the very same directories, it returns true. It only returns false in the context of an apache request. This makes me think it has something to do with the apache user (which is _www) not being able to access the symlinks. Troubleshooting this falls outside of my expertise.

Other notes:

  1. Yes, I have FollowSymLinks turned on in my apache config, and in fact, the directory where the symlinks in question reside is a symlink itself. Apache has no problem with it. Until PHP is_dir() is used.
  2. No, I cannot edit the PHP application and just fall back on is_link() and readlink().
  3. This exact same setup worked on my Snow Leopard/MAMP setup.

Any ideas?


Ah saw your comment on changing them to 777 but still wondering why it's not working. My solution below might not help you.

EDIT:

If you have access to /etc/apache2/httpd.conf,
edit it via sudo vi /etc/apache2/httpd.conf.
Then change these 1 of these lines or both of them

User _www
Group _www

Here is an example of my directory listing.

ace:remote-app ace (git::master)$ ls -al
total 72
drwxr-xr-x  24 ace  staff   816  7 Aug 00:24 .
drwxr-xr-x  11 ace  staff   374  4 Aug 13:46 ..
drwxr-xr-x   3 ace  staff   102 12 Jul 17:06 .bundle
drwxr-xr-x  14 ace  staff   476  7 Aug 02:29 .git
-rw-r--r--   1 ace  staff   100  1 Aug 19:20 .gitignore
-rw-r--r--   1 ace  staff     9  1 Aug 19:20 .rspec
drwxrwxr-x  10 ace  staff   340 14 Jul 15:58 public

Now my public directory has 775 permissions, meaning owner and group have full permissions while other users can only read and execute.
It depends if you want apache user to become ace from the default _www or the apache group to become staff from the default _www.

Once you've decided on which to change, restart apache.

/usr/sbin/apachectl graceful

And your page should now have access to the directories / files.
One thing to note is that you have to change ownership for files that have been already been written by your webpage as those have _www:_www ownership and you won't have access to them after the restart.
You can change their new ownership through this, -R is to make it recursive.

sudo chown -R newapacheuser:newapachegroup <path>


Did you check permissions/owner?

From the PHP manual: Note: The results of this function are cached.


I had a similar issue. I created the following link:

cd /home/mike/uploads
ln -s ./data /sites/www.test.com/docroot/data

Then I created a test.php file in /sites/www.test.com/docroot that just did the following:

$dir = "/sites/www.test.com/docroot/data";
"is_dir\t\t" .is_dir($dir) ."\n";

When I ran test.php from the command line, it would show up as is_dir was True, but when I loaded test.php from a browser through apache, it was False.

I went to /sites/www.test.com/docroot/data and did a

chmod -R 755 .

That didn't change anything. Then I realized, the parent to the actual symlinked dir needed proper permissions set (/home/mike/uploads). I did a chmod on that dir, and everything worked!


Check open_basedir directive in php config. That path should also be included. In linux, you can list multiple folders by separating them with a colon.

https://www.php.net/manual/en/ini.core.php#ini.open-basedir

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号