简体   繁体   中英

How can a PHP application log errors to a custom file in the: /var/log/httpd/ directory?

I am attempting to have a specific PHP script/application output to the following log file on CentOS7:

/var/log/httpd/custom_error.log

I have looked for different solutions with regard to this, but this SO question is the only closest answer I've seen, but still was unsuccessful.

Since I have multiple PHP frameworks/applications running (WordPress, Drupal, etc), I am using PHP's script-based override, and each script process uses its own override respectively. For example, the following does not work:

ini_set('error_log', '/var/log/httpd/wp_error.log' );

The ownership and permissions on that wp_error.log file are set to apache:apache 644.

In contrast, this works successfully when I have the following:

ini_set('error_log', '/var/www/wordpress/wp_error.log' );

Or:

ini_set('error_log', '/var/www/drupal/dru_error.log' );

To fix my problem I needed to change the ownership of the parent httpd folder in the path /var/log/ httpd / to apache:apache user/group:

sudo touch /var/log/httpd/custom.log
sudo chown -R apache:apache /var/log/httpd

Correct me if I'm wrong, but my research leads me to believe that Apache outputs its related logs to the syslog which is owned by root, which in turn writes logs to that folder.

However, if I change the ownership to Apache, root can still write to those log files, but now Apache and its related processes (eg, PHP) can directly write to that log folder as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM