I have seen several similar questions, but no answer worked in my situation, except that it probably has something to do with permissions.
A PHP script served by Apache tells me unable to open database file
.
When I print the path to that file, it returns a valid path, say DBPATH. The file does exist at that location; I gave it and its parent folder 777
rights; I gave them user:user
access, where user
is the sudoer that all script files belong to. I did the same to the whole htdocs/
folder, just in case.
When I print file_exists(DBPATH)
, it returns false. Is is most likely a matter of permissions, but I don't know what I should change for PHP to have access rights. I tried apache:apache
, too. I cannot su apache
(user not available).
My scripts are in htdocs/
. DBFILE is somewhere out of it (I tried /tmp/test
, all in 777
, but no luck either).
No safe_mode, PHP 5.4 freshly installed, CentOS7.
Please someone give me a clue at least to help debug it. Maybe such as: how can I check whether my file will be readable from apache/my php script, without running the script itself? How can I get the name of the user that is used to execute it?
Solved, more or less.
To debug I had the idea to move DBFILE to the same folder where the PHP script lives, and check it can find it - it did. Then I move DBFILE one folder after another in the tree to see where it stopped finding it.
It occurs that if only one of the folders in the whole path does not have execute rights for all users (xx5), the file cannot be found and file_exists
returns false
.
So the solution was to create another folder in a totally executable place (/var/www/data/
worked after chmod 755 data
), and move the file there.