I can't specify a custom error log in PHP

3.4k views Asked by At
ini_set('error_log', $custom_error_log_location);  
print ini_get('error_log');

The result of the above code? Nothing! It literally prints nothing as the value of ini_get('error_log'). I'm running this on an Apache server. I investigated the Apache configuration for my website. The Apache configuration has its own error log setup through the ErrorLog directive. Here's the thing: I'm running another website on the same server, with a similar Apache configuration, and on that site I CAN specify a custom error log in PHP.

I also checked the site's php.ini file. Nothing on logging there. What I want to know is, is there some configuration in either Apache or php.ini that would prevent me from modifying where the error log file is located?

3

There are 3 answers

2
aaz On BEST ANSWER

If safe_mode or open_basedir are in effect, ini_set("error_log") is restricted by those settings (because you can write anything in the opened file with error_log()).

The restriction covers both runtime and .htaccess, but you can use the php_value directive to set it in the virtual host configuration file.

0
William On

It turns out I had safe_mode on, that's all.

1
howanghk On

The error_log setting belongs to PHP_INI_ALL which can be set anywhere. So there should be nothing wrong with your code.

By "prints nothing as the value of ini_get('error_log')", it might be your $custom_error_log_location is empty or null, I'd suggest a var_dump() on the $custom_error_log_location and ini_get('error_log') for debugging, instead of print.