Solved

enabling error logs in php

Posted on 2014-10-21
6
266 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 83

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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 83

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 109

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 62

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Fine Tune your automatic Updates for Ubuntu / Debian
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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.:
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

815 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

8 Experts available now in Live!

Get 1:1 Help Now