0

I have an apache2 server running on my Linux machine. I edited the file /etc/php5/apache2/php.ini by setting include_path to

include_path = ".:/usr/share/php:/var/www/subdir"

To make sure I did not change the wrong file, I also edited all other php.ini files (there was one more) I found on my computer and checked the output of phpinfo() which printed the correct include_path from above. (I also restarted apache2.)

However, when I use lines like

use some\name\space;
require_once('./subsubdir/file.php');

in a file start.php (which lies in another directory /var/www/subdir/anothersubdir/), the require_once command does not work, as I get the following error in the apache log file

[error] [client 127.0.0.1] PHP Fatal error:  require_once(): Failed opening required './subsubdir/file.php' (include_path='.:/usr/share/php:/var/www/subdir') in /var/www/subdir/anothersubdir/start.php on line x

I also tried

require_once('/subsubdir/file.php');

but it did not work. How do I have to inlcude file.php when I have set the include_path as shown above ?

Thanks a lot in advance !

2 Answers 2

1

The first questions I would be asking myself are:

  • is the webserver running in a chroot environment?
  • what are the permissions on the target file?

And a simple way to answer both of these would be:

print getcwd() . "<hr />\n";
$t='/var/www/subdir/anothersubdir/subsubdir/file.php';

function show_permissions($path) 
{
   if (strlen($path)>1) {
       show_permissions(dirname($path));
   }
   if (is_readable($path)) {
       print "Permissions for $path: " . var_export(stat($path)) . "<br />";
   } else {
       print "can't read $path <br /> \n";
   }
}

(my money would be on a permissions problem - not a path issue)

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the responses! Indeed, is_readable yields 'false', which, in my opinion, means that the file cannot be found, as I set the permissions of file.php to rwxrwxrwx. Also, using relative paths (i.e. ../subsubdir/file.php) works fine, even without increasing permissions. (But using relative paths is a mess in my opinion, since I have several files in several directories that require each other.) By the way, getcwd() yielded the expected output, namely the directory in which start.php lies. Well, there would always be the option of saving the root directory in a global variable ...
"means that the file cannot be found...rwxrwxrwx" - not necessarily, the directory it resides in must be readable too. "using relative paths ...works" then most likely the php is running in a chroot jail. "getcwd() yielded....the directory in which start.php lies" - these three statements are not consistent
0

Try rebooting Apache, to clear the internal cache.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.