I've narrowed my problem down somewhat.
When I run "error_log('hey');" from the command line it dumps to STDOUT. But if I run the same code from my web interface (Apache) it puts the error in the error log.
I've checked both ini files, the one Apache is using, and the one in /private/etc (I'm on a Mac running MAMP). Both error_log variables point to the exact same place.
And when I run
echo ini_get('error_log');
The value is the same on the command line as it is in the browser.
What ini setting is misconfigured here? This is quite annoying, as more than just error logging is broken. It's affecting my include paths as well :/
What are you trying to accomplish? Within apache, stderr goes into the error_log... the error_log() function documentation states that by default it logs to the server's error log. If you want to log to a different destination, use the message_type and destination parameters.
You probably need to edit the following config file:
/Applications/MAMP/conf/php5/php.ini
MAMP uses it's own Apache server, which by default runs on port 8080. You probably want to turn off the Apache server in the System Preferences -> Sharing.
Also, try running a PHP file containing:
<?php phpinfo(); ?>
This will tell you which php.ini is actually being read by Apache.
Will
A reason for error_log displaying in the console, and not in the log file might be because of a problem with permissions -- I don't really know MacOS, but as it's UNIX-based, I'm guessing that :
The log file used by Apache belongs to a specific user
When running the script from the console, you are not that user, and you don't have write-access to the log file
If it can't log to the log file, I suppose that error_log is writting to the standard output for error (stderr), which is generally the console.
This comment on the manual's page seems to indicate this might be the cause of your problems (quoting) :
it seems that PHP logs to stderr if it
can't write to the log file. Command
line PHP falls back to stderr because
the log file is (usually) only
writable by the webserver.
Also, make sure the log_errors and display_errors are properly configured in the php.ini file used in CLI :
log_errors boolean
Tells whether script error messages
should be logged to the server's error
log or error_log. This option is thus
server-specific.
And :
display_errors string
This determines whether errors should
be printed to the screen as part of
the output or if they should be hidden
from the user.
Value "stderr" sends the errors to
stderr instead of stdout.
The relevant ini setting here is display_errors.
From the command line a value of On will dump the errors to STDOUT; stderr will divert them to STDERR and Off will suppress them. For Apache only On and Off make any sense.
The odds are that the ini file for Apache has display_errors = Off whilst the one in /private/etc has display_errors = On.
The error_log directive tells PHP where to log errors to, but it also requires log_errors to be set to On, otherwise it has no effect. (Again, chances are the ini file in /private/etc has log_errors = Off.)
Related
Basically, I have an issue whenever PHP should show an error; it won't load the .php file at all.
For example, let's say that I make a mistake while writing:
<?php
function foo($value) { return $value; };
foo(); //missing value, should display a warning or error
?>
That won't show an error, it will just say "This page isnt working".
I checked my php.ini file, but what I found inside seems legit:
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
What could be the cause of this issue? And of course, how to solve it?
You are most probably looking at the wrong error log file.
For PHP there are basically 3 options, depending on what error_log in php.ini is set to. To determine the correct value, add a file with the contents <php phpinfo(); and open it in your browser. This should show a list of all php settings. I recommend this method instead of just opening php.ini because it avoids confusion that might be caused by multiple php.ini and conf.d files.
In that page, search for error_log. This setting determines your log location. If it is not set, that means that PHP is logging to the SAPI interface. Look in your your webserver logs (location depends on OS and used webserver, for Ubuntu and Apache it would be /var/log/apache2/error.log).
If there is a file path in error_log that is the path of your PHP error log. Just open it and the error should be there.
If error_log is set to syslog, PHP logs to your system log. For windows, that is the event log (can be opened by searching for "event log" from the taskbar). For Unix that is the syslog, usually /var/log/syslog but might vary depending on configuration and distro.
Please note that in case you are using php-fpm there are additional FPM log settings, which you also would need to check.
I ran phpinfo() and the error_log directive simply says error_log. What file is that referring to? i.e. what would the full path to the error_log be?
Quote from the documentation:
error_log string
Name of the file where script errors should be
logged. The file should be writable by the web server's user. If the
special value syslog is used, the errors are sent to the system logger
instead. On Unix, this means syslog(3) and on Windows NT it means the
event log. The system logger is not supported on Windows 95. See also:
syslog(). If this directive is not set, errors are sent to the SAPI
error logger. For example, it is an error log in Apache or stderr in
CLI.
So, when the value is not set (which is the default) it will be sent to the parent error logger, which is apache (if run via it) or stderr if you run the script on the command line.
If you use the script via apache you will have to look at the apache error log, usually in /var/log/apache or /var/log/httpd, depending on your distribution. You can check the apache configuration file for the exact location.
Edit:
I just noticed I misread your question, I guess you mean error_log has the actual value error_log?
I just did some testing. When I set error_log to a value like php_errors.log PHP still writes the error messages to the apache error log. It behaves as if the value was empty. When I set the value to a full path (e.g. /tmp/php_errors.log) then it writes the errors to the specified file.
So I guess in your case it writes the errors to the apache error log file.
Of course you can set your own log file be adding
ini_set("error_log", "/tmp/php_errors.log");
to your PHP files where you need it (if it hasn't been disabled by an administrator).
When the value simply says error_log (or error_log = error_log in your php.ini file), that means the errors will be written to a file called error_log in the same directory that the error occurs.
So, if you have a file called index.php in /home/user/public_html/ that throws an error, the error will be written to: /home/user/public_html/error_log.
If you have file called resize.php in /home/user/public_html/admin/images/ that throws an error, then the errors will be written to: /home/user/public_html/admin/images/error_log
Source: Display and log errors for PHP
Open your php.ini file.
Check the path against error_log.
On Windows 10, IIS 10.0.18362.1, I set this in file php\php.ini:
error_log = "C:\tmp\php_errors.log"
or
error_log = C:\tmp\php_errors.log
or
error_log = \tmp\php_errors.log
phpinfo() shows:
error_log C:\tmp\php_errors.log or \tmp\php_errors.log
Sometimes directly, but always after iisreset (recycling the application pool).
That is where the file is saved.
Without pad: error_log = php_errors.log it will be written where the error occurs. It has already been mentioned.
Though I have read lots of posts and pages concerning the issue (shown below), I guess I'm missing something here. The mais issue is: my PHP errors are not being logged to the file specified nor to the system event log.
My phpinfo() shows: Windows Server 2003, PHP 5.3.6, log_errors = On, error_log = C:\\errorphp.log
I have tried both error_log = C:\Inetpub\logs\php.log and error_log = syslog in php.ini to no effect (either one at a time).
I have:
restarted IIS after every php.ini change
granted the IUSR_XXXXX User Modify permissions on the folder AND the file
tried leaving the directory blank and letting PHP create the file
had a headache.
Any help is much appreciated.
references:
PHP Manual - PHP on IIS 6
Store PHP errors in a log file
IIS PHP doesn't log errors to log file
My php error log file is empty
Running a defect php file cause error 500
Logging PHP to Windows Event Log
In my case, setting
fastcgi.logging = 1
in php.ini solved the issue and I do have the log file working now (I left the file creation to php itself, my directory was blank)
I'd never guess that as the php.ini itself states (right above the stated config)
; Disable logging through FastCGI connection. PHP's default behavior is to enable this feature.
Go figure.
Have you
checked your error_reporting level
tried setting a log file inside the document root (incl. permission to write) to see if any restrictions apply?
I have a server setup where a test script with just phpinfo() works fine.
When I try to run my application on it, it shows up as a blank screen.
I am calling index.php from the browser. The first few lines are as:
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
require_once('codelibrary...
Yet, the screen continues to be blank.
Edit 1
Here's the structure of the files:
/.htaccess
/index.php
/codelibrary/inc/user-top.php
/codelibrary/inc/variables.php
/codelibrary/inc/config.php
index.php
<?php
require_once('codelibrary/inc/user-top.php');
...
/codelibrary/inc/user-top.php
<?php
require_once("./codelibrary/inc/variables.php");
...
/codelibrary/inc/variables.php
<?php
include_once('config.php');
...
I thought the referencing here might be a problem, so I changed it to:
require_once("./codelibrary/inc/config.php");
as well, but no luck.
Edit 2
Ah ha! Thanks Col and TopQ for pointing out that I should look at the log file, it says:
[10-Sep-2010 17:06:02] PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20090626/suhosin.so' - /usr/local/lib/php/extensions/no-debug-non-zts-20090626/suhosin.so: cannot open shared object file: No such file or directory in Unknown on line 0
Try setting display_errors from a .htaccess file
php_flag display_startup_errors on
php_flag display_errors on
php_flag html_errors on
Use "view source" in your browser to see if anything is being written by your script that the browser might not be rendering visibly.
EDIT
If you're getting an http 500 response, then you can always do a php lint check on your script from the command line:
php -l <filename.php>
An extremely useful and oft-forgotten check on the syntax of your code.
Check the PHP error log. Usually syntax error or missing dependencies.
The problem is possibly the following: The error occurrs before your script runs (i.e. while parsing. Probably some syntax error). Since your script does not run, the error-level cannot be changed dynamically. You need to set error_reporting in your php.ini, or try fire's suggestion, which should produce equivalent results.
As noted in the other answers here if there is an error present in your script it will fail to set the error levels dynamically.
You can add the proper directives to either the .htaccess file in the current directory, the webserver config or the php.ini file (http://php.net/manual/en/errorfunc.configuration.php). You need to prefix those with the php_flag directive a la php_flag display_errors on.
If you can't add the commands to the .htaccess files it is most probable that your server config does not allow for overrides for those properties. Consult with the server maintainer for either changing these values, allowing you to override these directives on a per-folder basis and having access to error logs for your virtual hosts.
Considering that this is a script that will be executed by a user outside of your group (the browser/webserver) i would think that the file should be set with permissions 755 as this allows the you to make changes and noone else yet ensures that the browser can execute the script (755 -> -rwxr-xr-x)
I can't see any PHP errors. I have tried every trick I can find to turn error reporting on, but nothing works.
display_errors is on and error_logging is on, but when I view any page with an error, I get a blank page.
/var/log/php.log does not exist.
if I set a local logfile, Nothing gets created.
The file I have been testing with is
<?php
ini_set('display_errors',1);
error_reporting(E_ALL|E_STRICT);
ini_set('error_log','script_errors.log');
ini_set('log_errors','On');
$a=
phpinfo();
?>
any other ideas?
You probably need to set it in .htaccess, httpd.conf or php.ini (depending on your server or hosting company). You most likely have a parse error, which means your script never gets to the point where it can turn on the error reporting.
Have you tried editing the actual ini file as opposed to trying to change it at runtime? You can also try using ini_get('display_errors'); to see if your change took effect. If neither of those work I would say your installation is either faulty or very restricted.
Run phpinfo() as the first thing in the script, before you try any of the ini_set options. If your host has those ini functions disabled/restricted, you'll most likely not ever get to phpinfo.
Does the userID the webserver's running under have write permissions in the directory you're running this script from? It could be failing to open your test log file and kill the script that way.
Once you get some phpinfo() output, you'll be able to see if/where PHP is logging errors. It could be going into the server's general error_log, or some other location entirely.
i solved this problem by my hosing website
cpanel-> php config ->display error on