Why is Linux execute bit needed for PHP's file_exists() function to work properly

This question is for my understanding, I can live with they way things are, but, if I could change it that would be even better.

Here's the issue: when file_exists() is used in PHP running under Apache, the function will not return TRUE as it should unless the file has the group execute bit set. This doesn't make sense to me because I thought the execute bit was only need for files that were to be executed. A file being examined by an executing piece of code should read just as long as the read bit is set as far as I know.

A little more information:
    The file is a .png, e.g.: image.png.
    The distro is OpenSUSE 11.4
    PHP is version 5.3.8
    Apache version is 2.2.17
    The permissions and owner of the file being read are:  754 reg:web-dev
    Apache is running as user wwwrun:www. It has the group web-dev added to it as well.
    If the file's permissions are 744 PHP's file_exists() will always return FALSE
    If the file's permissions are 754 PHP's file_exists() will return TRUE to show that file exists (as it should)

The annoying part about this is that there are many PHP files that are actually being executed but they don't need more than 644 to execute so why would file_exists() suddenly need the group execute bit as well (654 or 754).

A second part to this question is, is this something that could be changed somehow? I.e., make it so only the read bit is required. Then more reasonable permissions for an image could used like 644 or even 640.
LVL 1
RegProctorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

BlazCommented:
Are you using safe_mode? Not documented exacly as your experience, but worth a try to set it to false.
http://www.php.net/manual/en/function.file-exists.php



0
xtermCommented:
How exactly are you calling this function?  Because in my experience, it does not operate this way.  Take the following code where I manually created empty files foo (mode 744) and bar (mode 754).  I purposely didn't create file baz.


xterm@dellxps:~/Documents/ee$ ./fe.php
File foo exists
-rwxr-xr-- 1 xterm xterm 0 2011-12-06 02:24 foo
File bar exists
-rwxr--r-- 1 xterm xterm 0 2011-12-06 02:24 bar
File baz doesn't exist


<?php

$files=array("foo","bar","baz");

for ($i=0; $i<count($files); $i++) {
        if(file_exists($files[$i])) {
                echo "File $files[$i] exists\n";
                system("ls -l $files[$i]");
        } else {
                echo "File $files[$i] doesn't exist\n";
        }
}

?>

Open in new window

0
RegProctorAuthor Commented:
@Blaz  I checked, it looks like safe mode is off.

@xterm  You can't really get it wrong "if (file_exists('someFile')) ...", I doubt it's a php issue. The reason I gave all the info. on users. groups and permissions is because I am sure it's a Linux setup issue in some way. Linux has a myriad of things you can do with it and I am sure this is just some quirk I need to learn about.
0
What were the top attacks of Q1 2018?

The Threat Lab team analyzes data from WatchGuard’s Firebox Feed, internal and partner threat intelligence, and a research honeynet, to provide insightful analysis about the top threats on the Internet. Check out our Q1 2018 report for smart, practical security advice today!

xtermCommented:
Well, if they are truly 744 and 754, both files are still world-readable, so the owner/group doesn't matter.  My guess is that the two files are in different directories, one of which is unreadable.  Remember, if Apache doesn't have a permission to descend into a directory, it doesn't matter what the file perms in there are - they won't be visible.
0
RegProctorAuthor Commented:
I am only talking about one file, not two different files. I changed the permissions on the one file and tested the results. It's not a matter of a different directory or something like that. I have been administering my own Linux boxes for several years so a simple obvious issue like that I have already ruled out.
0
RegProctorAuthor Commented:
Here's what I found out. Some commands in PHP require the execution bit to be set in the permissions. So, regardless of the exact answer to my question, I should set the bit just so I don't get "stuck" sometime when some command runs on those files that definitely does need that bit.

It's not a perfect answer but it's good enough as it's certainly not worth tracking down any further.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RegProctorAuthor Commented:
It's the closest we have to an answer.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.