Aleksiv95
Aleksiv95

Reputation: 35

PHP errors written to wrong log

My Linux server is running PHP 7 as a CGI on Apache2. In php.ini I have

error_log = /var/log/apache2/php.log

Now, I have two problems:

1) All PHP errors go to /var/log/apache2/error.log instead of php.log. I have edited the right php.ini because ini_get('error_log') returns the full path of php.log in PHP.

2) When I try to open either of those files in PHP, I get permission denied. I have chmod'd both files to 777, but PHP is still unable to access them.

The server has been restarted multiple times so the configuration changes apply. My Apache configuration is this:

ErrorLog ${APACHE_LOG_DIR}/error.log

ScriptAlias /local-bin /usr/bin
AddHandler application/x-httpd-php7 php
Action application/x-httpd-php7 /local-bin/php-cgi7.0
<Directory "/usr/bin">
    Require all granted
    AllowOverride All
</Directory>

How can I redirect PHP errors to the right file, and also make it readable for PHP? Thanks in advance!

Upvotes: 1

Views: 514

Answers (1)

razz
razz

Reputation: 10110

You need to change the owner and the group of the log directory and the log file/s (if already exist/s) to www-data:

sudo chown -R www-data:www-data /path/to/log/directory

Dont change the directory permissions to 777 as it might cause security issues, use 775 instead. For the log files use 664.

You might also want to add your system user to the group www-data if not already a member (use groups command to check for your existing groups), a system reboot is required after that for the changes to take effect:

sudo adduser user www-data #change 'user' to your 

Upvotes: 1

Related Questions