Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

enabling error logs in php

Posted on 2014-10-21
6
Medium Priority
?
283 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 84

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 800 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 400 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 84

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 800 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 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 400 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 62

Accepted Solution

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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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.
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

972 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