1
votes

I have two servers, one is the public server, one is my development server.

Both have the same OS version (CentOS7.7), both use the SAME setup for php (remi), both have the SAME php.ini, both have the same packages (plus versions!) installed - except a few non apache/php related packages (development machine) they are nearly identical machines.

Both used to log all php errors and error_log() to the php.ini defined error_log file: "/var/log/php". I have just updated to php 7.3, everything is working fine EXCEPT the logging. Now the development machine logs to php log while the public machine logs to the apache error logs.

I cannot work out why this is the case and I need some help with this, please.

On BOTH machines in the php.ini file I have set:

display_errors = Off
display_startup_errors = Off
log_errors = On
html_errors = Off
error_log = /var/log/php
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT

On both machines the permissions are correct:

[user@PUBLIC /var/log/httpd] #>ls -la /var/log/php
-rw-rw----. 1 apachedaemon apachedaemon 199923 Nov 19 10:11 /var/log/php
[user@DEVELOPMENT /var/log] #>ls -la /var/log/php
-rw-rw---- 1 apachedaemon apachedaemon 158103 Nov 19 10:58 /var/log/php

On both machines I have a php script:

<?php
ini_set('log_errors','On');
ini_set('display_errors','Off');
ini_set('error_reporting', E_ALL );
error_log("---------------------------------- start error test");
error_log($NotDefined);
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>php error test</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<h1>php error test</h1>
<p> </p>
</body>
</html>
<?php
error_log("end");
?>

On the public machine I see this:

==> 1.2.3.4_ssl_error_log <==
[Tue Nov 19 10:43:07.257073 2019] [php7:notice] [pid 4462] [client W.X.Y.Z:44844] ---------------------------------- start error test
[Tue Nov 19 10:43:07.257126 2019] [php7:notice] [pid 4462] [client W.X.Y.Z:44844] PHP Notice:  Undefined variable: NotDefined in /PATH/errorTest.php on line 8
[Tue Nov 19 10:43:07.257137 2019] [php7:notice] [pid 4462] [client W.X.Y.Z:44844]
[Tue Nov 19 10:43:07.257147 2019] [php7:notice] [pid 4462] [client W.X.Y.Z:44844] end

On the development machine I see this (this is the correct way):

==> /var/log/php <==
[19-Nov-2019 10:30:28 Australia/Melbourne] ---------------------------------- start error test
[19-Nov-2019 10:30:28 Australia/Melbourne] PHP Notice:  Undefined variable: NotDefined in /PATH/errorTest.php on line 8
[19-Nov-2019 10:30:28 Australia/Melbourne]
[19-Nov-2019 10:30:28 Australia/Melbourne] end

What am I doing wrong? Why does one server log to php error log while the other server logs to the apache error logs?

This IS annoying, as ALL php error log messages are all over the place and not in ONE log file as it USED to be before upgrading to php7.3

Please help, thanks.

1
in the script you have posted, where you initialize $NotDefined?Alberto Sinigaglia
@AlbertoSinigaglia the entire point of this post/question, I need to raise an error to have it logging ...Jobst
You are getting an error because error_log as first parameter want a string, and you are passing him a variable never initialize before, so it’ an undefined variable... what do you want to do with error_log($NotDefined)?Alberto Sinigaglia
I KNOW! I WANT an error! I need to figure out why the PHP errors show up differently on the production and development server. On the production they end up in the apache error log while on the development server they end up in the php error log!Jobst
on your php.ini you should have this error_log = /var/log/php-scripts.log that says to the error_log function where to put the logsAlberto Sinigaglia

1 Answers

1
votes

I tried with various PHP versions (7.2, 7.3, 7.4) and I cannot reproduce.

I suspect a write access permission issue:

  • by default /var/log is owned by root and not writable by normal users, such as apache
  • /var/log/php can be created by any user (root ?) if any PHP script was run before httpd service create this file

This can be check by running and tracing a httpd debug process

# service httpd stop
# strace httpd -X

Also

# ls -al /var/log
# ls -al /var/log/php

Allowing normal users to log in /var/log seems a bad practice (security PoV).

And altering php.ini is a very bad practice, especially in this case, where each user need a different setting.

Read How to change configuration settings

I recommend:

Create a "apache" owned directory for log

# mkdir /var/log/apache
# chown apache  /var/log/apache

And configure the httpd service to use it, in each vhost configuration file

php_admin_value error_log /var/log/apache/vhostname_php_error.log

I also recommend to not alter RPM default provided configuration files, but create your own specific files

  • /etc/php.d/foo.ini
  • /etc/httpd/conf.d/bar.conf
  • etc

P.S. fallback on default SAPI logging is the standard behavior of PHP when it cannot open the file configured by error_log directive.