PHP returns error 500, but nothing is logged
Asked Answered
S

13

69

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 ubuntu 10.04 with the standard apache and php from the ubuntu repo with apt-get.

Saharan answered 22/8, 2011 at 14:30 Comment(1)
Apache and PHP both from the standard ubuntu repo with apt-getSaharan
B
58

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.

Bainbridge answered 22/8, 2011 at 14:37 Comment(9)
It was that. CodeIgniter apparently loves to use these in there framework, chalk up another reason I dislike CodeIgniter.Saharan
this exactly. in my case CodeIgniter's return @mysql_connect(... was masking the fact that I had failed to install php's mysql module on a fresh server. stupid me, hours wasted, lesson learned.Reservoir
Here for CodeIgniter. Can you explain the actual fix? Just remove @?Suspiration
@jake The answer is self-explanary. Removing the '@' will re-enable error reporting.Bainbridge
@LucM That is much easier said than done for something like CodeIgniter. There are thousands of @ symbols scattered through their codebase since they are used for comments as well. So the suggestion of removing @ indiscriminately is effectively useless. Maybe the lesson here is not to use CodeIgniter.Suspiration
@Suspiration most IDE's allow regex in find and replace, also find in path. So not useless at all.Requiem
@MichaelHanon It is not a question of whether regex is supported or possible. Search and replace can be quite error-prone for large projects. For example, simply removing all "@" symbols from the codebase could easily break code that manipulates email addresses. A small change consisting of a few lines or less is generally preferable to applying a regex replacement to an entire codebase. If your changes are so vast that they can only be feasibly completed with search and replace, how can you possibly expect to verify them all in code review?Suspiration
@Suspiration PHP Storm "Replace in Path" displays each piece of code before you change it, or you can replace all. Either way, i'm sure they added all those @ for a reason and will probably break if removed.Requiem
@MichaelHanon As I mentioned in my May 7 comment there are thousands of these @ symbols scattered throughout CodeIgniter so individually verifying each search and replace result is not feasible, and even if it were the process would still be error-prone due to the sheer number. As you pointed out, they must be there for a reason, so maybe the best advice is not to just remove them all.Suspiration
C
12

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.

Crotty answered 9/12, 2018 at 20:17 Comment(0)
C
10

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.

Chess answered 12/10, 2017 at 13:44 Comment(3)
This completely broke my website - running PHP 7.4.Stipe
In this case, maybe your issue is upstream @Stipe (like 500 error), so, go to your /var/log/apache2/error.log and see what's in.Chess
this solution is good for a testing environmentTrug
R
7

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).

Retract answered 22/8, 2011 at 14:35 Comment(0)
G
6

In the past, I had no error logs in two cases:

  1. The user under which Apache was running had no permissions to modify php_error_log file.
  2. 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.
Grouch answered 13/6, 2013 at 15:48 Comment(0)
M
3

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.

Macule answered 4/1, 2017 at 10:25 Comment(0)
C
2

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 :-)

Calumniation answered 19/12, 2013 at 7:28 Comment(0)
T
2

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.

Towardly answered 9/3, 2014 at 10:1 Comment(0)
G
1

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.

Grandiose answered 1/10, 2019 at 6:40 Comment(0)
T
1

If you

  • Are getting an intermittent Error 500 when submitting forms, and
  • You can't get a PHP error message to display even with display_errors(-1)

Then the problem may be

  • Your web hosting company may have a ModSecurity plugin installed, that checks $_POST for certain regex matches

You can verify this by

  • Going to /home/youraccount/log/.../.../error.log, which should have the detailed error logs that you can't see in browser

The fix is

  • Go into your web hosting control panel, find a setting that says "Extra Web Security?" or similar, and turn it off for that domain. You should be able to google for info specific to your web hosting company.
Tamayo answered 2/3, 2023 at 8:13 Comment(0)
D
0

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

Darnelldarner answered 22/8, 2011 at 14:32 Comment(1)
I think you've misunderstood the question.. his PHP error log is enabled but this particular 500 internal server error was not being logged. I've got this problem now in Laravel for an error generated by trying to access a private method. Other 500 errors get logged but not that one... can't figure out why :(Vinery
C
0

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.

Channing answered 6/2, 2017 at 17:35 Comment(2)
Apache should already have root permissions regardless of OS and should therefore be able to write to any file, never mind it's own log file.Stirrup
No Apache should never have root permission. That would be a severe security breach.Metanephros
S
0

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.

Schechter answered 2/5, 2020 at 21:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.