0

Setup: CentOS 6.6, Apache 2.2.15, php 5.5.21

I 'm building a php script that displays the content of the /var/log/httpd/error_log file. Unfortunately, it does not work. The error message states:

Permission denied in /var/www/domain.com/tools/server-logs-viewer.php on line 405

Line 405: $f = fopen($filename, "rb");

I've chmoded 0777 the file, just to check, still no-go. So I assume the message refers to file ownership. The log file is owned by root:root whereas the php script is owned by apache:apache.

What can I do to give apache enough read access to the file, without compromising the error reporting process ?

1

I has been ages that I am not doing anything in PHP but, without further info there would be a couple system configuration elements and php.ini settings I would check:

path to the log file

Please, ensure that the user running apache is able to reach the directory where the file is. That means it should have r+x access to the directories along the path.

php.ini settings

Please, have a look at the php fopen manual:

  • safe_mode: depending on the version you are using (it seems it was removed in 5.4.0)
  • open_basedir: refuses to open anything not in this tree.

SELinux, AppArmor

Are you running SELinux or AppArmor? That could prevent the apache process to access the file despite of the permissions.

Best regards

  • Your very first advise was the right trick, thank you – pixeline Jan 31 '15 at 9:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.