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.
Related
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.
I cannot view PHP error on Apache of my mac because every time when I changed from php.ini file to display_error On. But when i restart and open the php.info file, it still says display_error Off. Searched for all php.ini file and changed all off to on but still same result. Help please
Use error_reporting(); at the begining of your PHP main file. It will ignore php.ini and obey the error level you set there.
Also, check that your php.ini is not beign use / locked before you make changes on it?
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
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.)
I am trying to get my install of PHP under IIS to display errors, but I'm having no luck at all. I tried
error_reporting(E_ALL);
in the script, and nothing shows up, just a blank screen.
I tried editing my PHP.ini file and setting
error_reporting = E_ALL
display_errors = On
Also tried
error_reporting = E_ALL
display_errors = stdout
but nothing is showing up on the screen at all when my scripts throw errors.
Any advice?
Ensure that you're editing the PHP file in the correct location; IIS can look for a php.ini file in C:\WINDOWS rather than the install location of the PHP ISAPI or CGI module. Check the output of phpinfo(); to determine you're editing the correct php.ini file. Also, you need to restart the IIS service (or the computer overall) before those changes will be put into effect.
Sorry to resurrect a dead post but I had a similar issue and solved it by doing this in my PHP code:
ini_set('display_errors',1);
error_reporting(E_ALL);
This obviated the need to edit the server config and also allowed me to do this in just the method that I thought was problematic.
Perhaps IIS is blocking your errors from displaying.
Try:
Open inetmgr (Start -> Run -> inetmgr -> enter)
click on the site
select error pages (double click on it)
on the right hand side click on “Edit Feture Settings”
In the dialog that appears, select “Detailed Errors”.
Save and close.
Restart IIS just to be sure.
Posted for the sake of googlers like me.
on php.ini in the php installation path change the value of error display to on