In /var/log/apache2/error.log I able to trace http 500 error, Only I able to log error when I hit url from browser but when I call api either via ajax call or by postman, then any syntax error(500 error) not logged in apache2/error.log . Please tell me how can I log this one as well. Thx! in advance.
If you're getting an error and there's nothing wrong with your Apache, then there's probably an issue with your PHP. Look in your PHP error log for an error. If PHP is not logging errors then you need to change the php.ini file so that log_errors is 1 and error_log is the file name you want errors to be logged to. (I recommend "error_log". This will log all errors to the file error_log in the same directory as the file creating the error.)
Related
I am having an issue when I have a php application that is returning an internal server error (500) however nothing is showing up in the error log.
Now I know there are error with what I am trying to run, I know I have missing some files and what not but something should show in the apache error log (otherwise how are I supposed to know exactly what I am missing).
I created a test script is errors it in under the same vhost configuration and those error show up fine so everything seems configured right as far as php/apache. Are there certain php errors that does show up in the error log (php is configure to display any type of notice, warning, , error, fatal error, etc...)?
This is running on ubunut 10.04 with the standard apache and php from the ubuntu repo with apt-get.
Scan your source files to find #.
From php documentation site
Currently the "#" error-control operator prefix will even disable
error reporting for critical errors that will terminate script
execution. Among other things, this means that if you use "#" to
suppress errors from a certain function and either it isn't available
or has been mistyped, the script will die right there with no
indication as to why.
Copy and paste the following into a new .htaccess file and place it on your website's root folder :
php_flag display_errors on
php_flag display_startup_errors on
Errors will be shown directly in your page.
That's the best way to debug quickly but don't use it for long time because it could be a security breach.
If you still have 500 error and no logs you can try to execute from command line:
php -f file.php
it will not work exactly like in a browser (from server) but if there is syntax error in your code, you will see error message in console.
Maybe something turns off error output. (I understand that you are trying to say that other scripts properly output their errors to the errorlog?)
You could start debugging the script by determining where it exits the script (start by adding a echo 1; exit; to the first line of the script and checking whether the browser outputs 1 and then move that line down).
In the past, I had no error logs in two cases:
The user under which Apache was running had no permissions to modify php_error_log file.
Error 500 occurred because of bad configuration of .htaccess, for example wrong rewrite module settings. In this situation errors are logged to Apache error_log file.
For Symfony projects, be sure to check files in the project'es app/logs
More details available on this post :
How to debug 500 Error in Symfony 2
Btw, other frameworks or CMS share this kind of behaviour.
Here is another reason why errors might not be visible:
I had the same issue. In my case, I had copied the source from a production environment. Hence the ENVIRONMENT variable defined in index.php was set to 'production'. This caused error_reporting to be set to 0 (no logging). Just set it to 'development' and you should start seeing error messages in apache log.
Turned out the 500 was due to a semi colon missing in database config :-)
Another case which happened to me, is I did a CURL to some of my pages, and got internal server error and nothing was in the apache logs, even when I enabled all error reporting.
My problem was that in the CURL I set
curl_setopt($CR, CURLOPT_FAILONERROR, true);
Which then didn't show me my error, though there was one, this happened because the error was on a framework level and not a PHP one, so it didn't appear in the logs.
You need to enable the PHP error log.
This is due to some random glitch in the web server when you have a php error, it throws a 500 internal error (i have the same issue).
If you look in the PHP error log, you should find your solution.
see here in the doc of how to enable it in the php.ini
Be sure your file permissions are correct. If apache doesn't have permission to read the file then it can't write to the log.
What happened for me when this was an issue, was that the site had used too much memory, so I'm guessing that it couldn't write to an error log or displayed the error. For clarity, it was a Wordpress site that did this. Upping the memory limit on the server showed the site again.
SOLVED
I struggled with this and later on, I realized that I was working on PHP 5.6, so I upgraded to PHP 7.0, then I released there were comments placed by git for conflicting codes. I found something like this in my code <<<<<<<< But solved it.
I installed one product. I got error like this. I dont know how to resolve this. I checked Php.ini file, .htacess file and file permission too. All are correct. Anybody tell the solution.
Error Message :
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, webadmin#xxxxxx.xx and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
The reason why the 404 error showed was because it was trying to write the error to a log, which you do not have enabled:
First thing to do is if you can get in the admin section of your site, make sure you have error reporting set to on:
Here is how to enable error reporting:
system_configuration_ADVANCED_Developer (system>configuration>ADVANCED>Developer)
When you open that tab you'll see a section called "log settings" choose the following:
-enabled to yes
- System Log File Name: system.log (or you can replace the system with another word like magensys.log)
-Exceptions Log File Name: exception.log
Now both these log files can be found in /var_log (www.domainhere.com/var/log or if it's a local installation magentofolder/var/local)
Try reloading the page where this error occurs and if it does occur again, then open your error log to see the error.
Most of the time it's due to extensions not agreeing with what you are trying to accomplish.
Option 2) Go to app_etc_local (app/etc/local) and delete the local.xml then reload your site and reinstall magento, this will not delete your site just reload your basic settings so you can everything back to normal.
If you could be a little more clear to what kind of product you were installing, where you were installing, etc... that would help pinpoint the error.
You need to check your php error log, if you don't know where it is you can do the following from your terminal:
$ -> `php -i | fgrep -i error`
You should see an entry for error_log. Tail that file and refresh the page, it should display the error.
Maybe this article
will help you. Try to use
<?php
# test.php
error_reporting(E_ALL);
ini_set('display_errors','On');
ini_set('error_log','my_file.log');
foreach(1 as $i);
ini_set('error_log','');
foreach(1 as $i);
ini_set('error_log','/dev/null'); #linux
foreach(1 as $i);
?>
I was facing this error because of wrong entries in httaccs file. Plz check your http access file
I have a page written in PHP. I do not have access to the server. I'd like to make so that instead of showing an error message when PHP encounters an error, it gives a 500.
PHP 5.2 by default sends HTTP 500 in case of fatal error, if display_errors is off.
If the hosting is with older PHP, you have to register your own error handler and possibly exception handler and redirect the user to your 500 error page. Try setting the display_errors and error_reporting variables in your PHP script as #Umang suggested.
you can create your own error handler and use it to send 503 status code to the client.
I am having an issue when I have a php application that is returning an internal server error (500) however nothing is showing up in the error log.
Now I know there are error with what I am trying to run, I know I have missing some files and what not but something should show in the apache error log (otherwise how are I supposed to know exactly what I am missing).
I created a test script is errors it in under the same vhost configuration and those error show up fine so everything seems configured right as far as php/apache. Are there certain php errors that does show up in the error log (php is configure to display any type of notice, warning, , error, fatal error, etc...)?
This is running on ubunut 10.04 with the standard apache and php from the ubuntu repo with apt-get.
Scan your source files to find #.
From php documentation site
Currently the "#" error-control operator prefix will even disable
error reporting for critical errors that will terminate script
execution. Among other things, this means that if you use "#" to
suppress errors from a certain function and either it isn't available
or has been mistyped, the script will die right there with no
indication as to why.
Copy and paste the following into a new .htaccess file and place it on your website's root folder :
php_flag display_errors on
php_flag display_startup_errors on
Errors will be shown directly in your page.
That's the best way to debug quickly but don't use it for long time because it could be a security breach.
If you still have 500 error and no logs you can try to execute from command line:
php -f file.php
it will not work exactly like in a browser (from server) but if there is syntax error in your code, you will see error message in console.
Maybe something turns off error output. (I understand that you are trying to say that other scripts properly output their errors to the errorlog?)
You could start debugging the script by determining where it exits the script (start by adding a echo 1; exit; to the first line of the script and checking whether the browser outputs 1 and then move that line down).
In the past, I had no error logs in two cases:
The user under which Apache was running had no permissions to modify php_error_log file.
Error 500 occurred because of bad configuration of .htaccess, for example wrong rewrite module settings. In this situation errors are logged to Apache error_log file.
For Symfony projects, be sure to check files in the project'es app/logs
More details available on this post :
How to debug 500 Error in Symfony 2
Btw, other frameworks or CMS share this kind of behaviour.
Here is another reason why errors might not be visible:
I had the same issue. In my case, I had copied the source from a production environment. Hence the ENVIRONMENT variable defined in index.php was set to 'production'. This caused error_reporting to be set to 0 (no logging). Just set it to 'development' and you should start seeing error messages in apache log.
Turned out the 500 was due to a semi colon missing in database config :-)
Another case which happened to me, is I did a CURL to some of my pages, and got internal server error and nothing was in the apache logs, even when I enabled all error reporting.
My problem was that in the CURL I set
curl_setopt($CR, CURLOPT_FAILONERROR, true);
Which then didn't show me my error, though there was one, this happened because the error was on a framework level and not a PHP one, so it didn't appear in the logs.
You need to enable the PHP error log.
This is due to some random glitch in the web server when you have a php error, it throws a 500 internal error (i have the same issue).
If you look in the PHP error log, you should find your solution.
see here in the doc of how to enable it in the php.ini
Be sure your file permissions are correct. If apache doesn't have permission to read the file then it can't write to the log.
What happened for me when this was an issue, was that the site had used too much memory, so I'm guessing that it couldn't write to an error log or displayed the error. For clarity, it was a Wordpress site that did this. Upping the memory limit on the server showed the site again.
SOLVED
I struggled with this and later on, I realized that I was working on PHP 5.6, so I upgraded to PHP 7.0, then I released there were comments placed by git for conflicting codes. I found something like this in my code <<<<<<<< But solved it.
my boss says "when I try to serf the website I get a server error... after a reload I get every thing back to normal". I think that he gets 500 error. how can I log it? I want to know when and where it happens. any ideas?
500 errors are logged in your web server's error log, for Apache that is usually error.log. You should be able to find all errors there, including the requesting IP and the exact message.
If you don't have access to the error logs, if you have Apache, you can try this in a .htaccess file:
ErrorDocument 500 /my_error_handler.php
my_error_handler.php would then send out an E-Mail to you or something. This won't give you the exact error message, though.
According to the comments, this is not the case on Apache, but is the case on IIS. If you think the error is related to your PHP code then it's possible this is what's causing the status 500 error.
There are several ini directives you can set to deal with server errors. I recommend having error logging switched on. See the following site for each ini directive:
http://www.addedbytes.com/drafts/php-ini-guide/php-ini-guide-error-handling-and-logging/
Add/Change/Uncomment the ones you want in your php.ini file.
With logging switched on, the following php code generates the following error string in the error log file:
<?php this_is_undefined(); ?>
error log -
[05-Jan-2010 12:44:29] PHP Fatal error: Call to undefined function this_is_undefined() in D:\websites\leaguers.co.uk\test.php on line 1