Php – How to get cURL errors to go into the correct log file

apache-2.2curlloggingPHP

I have a website running using Apache 2.2.22, PHP 5.3.10, and cURL 7.2.00. The relevant portions of the apache config is below, and you will notice that errors are sent to www.example.com_error.log.

<VirtualHost *:443>
    ServerName example.com
    ServerAlias www.example.com

    # *snip*

    ErrorLog ${APACHE_LOG_DIR}/example.com_error.log
    LogLevel warn
    CustomLog ${APACHE_LOG_DIR}/example.com_access.log combined
</VirtualHost>

However, when I use cURL from within PHP and turn verbose logging on using curl_setopt($connection, CURLOPT_VERBOSE, true); the output from cURL goes into Apache's error.log instead of the custom logfile I defined above. Why is this, and how can I get cURL's output to go into the correct log file?

Best Answer

Per some answers to this SO question, php logs to the default Apache server log (error.log) as you've already noticed. You can set the php log settings like so:

<VirtualHost *:443>
    ServerName example.com
    ServerAlias www.example.com

    # *snip*

    ErrorLog ${APACHE_LOG_DIR}/example.com_error.log
    LogLevel warn
    CustomLog ${APACHE_LOG_DIR}/example.com_access.log combined

    php_flag log_errors on
    php_flag display_errors on
    php_value error_reporting 2147483647
    php_value error_log ${APACHE_LOG_DIR}/php.error.log
</VirtualHost>

Alternatively, one answer in that SO question mentioned unsetting the error_log directive completely in php.ini to log to the relevant virtual host's logs, e.g. example.com_error.log.

Related Topic