Solved

enabling error logs in php

Posted on 2014-10-21
6
261 Views
Last Modified: 2014-10-28
Hi,

We have been struggling to enable php error logs in apache. We wanted the error logs to be generated in the folder where the error occurs.So, initially we set the following parameters, but it's not generating any error logs

log_errors = On
log_errors_max_len = 0
error_log = syslog

So, we changed it to syslog, but it's still not logging any php warn/errors to syslog also, though php config clearly shows so:
php -i|grep log
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
error_log => syslog => syslog
log_errors => On => On
log_errors_max_len => 0 => 0
mail.log => no value => no value


Why is apache is not overlooking the php config? or is there anything thats overwriting this setting?


Thanks
0
Comment
Question by:Starquest321
6 Comments
 
LVL 82

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 200 total points
ID: 40393772
Did you restart Apache so it would load the revised 'php.ini'?  Nothing will change until you do that.
0
 
LVL 36

Assisted Solution

by:Loganathan Natarajan
Loganathan Natarajan earned 100 total points
ID: 40393775
did you try full path on this line?

error_log = syslog

Open in new window

0
 

Author Comment

by:Starquest321
ID: 40393790
Yes. I restarted apache after every config change to php.ini, but of no use. Loganathan, if I give full path i.e. /var/log/messages, i will have to change the ownership to apache so that php can write to it. So, I didnt give full path. I thought 'syslog' is understood by apache and writes automatically to the system logs.

I, however tried giving a full path like /var/log/php_error_log, but that didnt' work as well
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 82

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 200 total points
ID: 40393817
Some systems have more than one 'php.ini', typically one for the web server and one for the command line.  Run 'phpinfo()' in a browser to make sure you are changing the correct one.  The entries you listed above show up in 'phpinfo()'.
0
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 100 total points
ID: 40394255
My system does exactly what you describe.  Here are my settings at PHP 5.4.34; bold is what I think may be in play.

display errors: On
display startup errors: Off
error append string: no value
error log: error_log
error prepend string: no value
error reporting: 24567 /* manually raised to E_ALL in scripts under test */
html errors: On
ignore repeated errors: Off
log errors: On
log errors max len: 1024
track errors: Off

If you have the Suhosin extension installed, remove it.  It's an artifact of poor programming practices from a decade ago.  It will not really make your scripts any safer and it will make your debugging much harder because it will silently truncate data and may hide certain error conditions.

Here is a little script that I run to find all of the error logs in my system.  Put it in the web root directory and it will traverse all sub-directories recursively to locate and display the error_log files.  For obvious reasons you may want to password-protect a script that shows this kind of information.

<?php // find_error_log.php
error_reporting(E_ALL);
ob_start();

// PUT THESE SETTINGS IN PHP.INI
// log_errors = On
// log_errors_max_len = 1024
// error_log = error_log

// PUT THIS SCRIPT IN THE WEB ROOT DIRECTORY
$path = realpath(getcwd());
$plen = strlen($path);

// THE ERROR LOG FILE NAME
$signal = strrev('error_log');


// IF THERE IS A POST-METHOD REQUEST TO DELETE THIS ERROR LOG
if (!empty($_POST['log']))
{
    // MAKE SURE WE ONLY UNLINK THE ERROR LOG FILE
    $test = strrev($_POST['log']);
    if (strpos($test, $signal) === 0)
    {
        unlink($path . $_POST['log']);
        echo '<h3>' . $_POST['log'] . ' Discarded</h3>';
    }
}


// SEE http://php.net/manual/en/class.recursivedirectoryiterator.php#85805
$objs = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST);
foreach($objs as $name => $obj)
{
    // PROCESS THE ERROR LOG ONLY
    $test = strrev($name);
    if (strpos($test, $signal) === 0)
    {
        $name = substr($name, $plen);
        $form = <<<EOD
<form method="post" style="margin:0; padding:0; display:inline;!important">
<b>$name</b>
<input type="submit" value="Discard?" />
<input type="hidden" name="log" value="$name" />
</form>
EOD;
        echo $form;

        // SHOW THE CONTENTS OF THE ERROR LOG
        echo '<pre>';
        print_r(file_get_contents($path . $name));
        echo "</pre>";
    }
}

$out = ob_get_contents();
if (empty($out)) echo '<h3>Good News! No error_log found.</h3>';

Open in new window

0
 
LVL 61

Accepted Solution

by:
gheist earned 100 total points
ID: 40403596
If PHP logs to syslog then apache has no way to capture those messages.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now