Internal Error 500 Apache, but nothing in the logs?
Asked Answered
A

13

155

I'm getting 500 Internal Server errors when I try to make an HTTP POST to a specific address in my app. I've looked into the server logs in the custom log directory specified in the virtual hosts file, but the error doesn't show up there so debugging this has been a pain in the ass.

How do I cause Apache to log Internal 500 errors into the error log?

Aurore answered 19/1, 2011 at 3:4 Comment(2)
I had same issue using PHP with virtual hosts....no errors (Apache2, Ubuntu). Ended up being missing PHP modules (mysql, json, etc.)Bourbonism
On ours, it was sending them to the access log (presumably because from Apache's point of view, it was working correctly and merely passing them along, from a deeper layer -- in our case, Passenger/Rails). Just putting this note here in case somebody is scratching their head.Harrus
I
8

Please Note: The original poster was not specifically asking about PHP. All the php centric answers make large assumptions not relevant to the actual question.

The default error log as opposed to the scripts error logs usually has the (more) specific error. often it will be permissions denied or even an interpreter that can't be found.

This means the fault almost always lies with your script. e.g you uploaded a perl script but didnt give it execute permissions? or perhaps it was corrupted in a linux environment if you write the script in windows and then upload it to the server without the line endings being converted you will get this error.

in perl if you forget

print "content-type: text/html\r\n\r\n";

you will get this error

There are many reasons for it. so please first check your error log and then provide some more information.

The default error log is often in /var/log/httpd/error_log or /var/log/apache2/error.log.

The reason you look at the default error logs (as indicated above) is because errors don't always get posted into the custom error log as defined in the virtual host.

Assumes linux and not necessarily perl

Internee answered 19/1, 2011 at 4:13 Comment(7)
I checked the server ErrorLog, and there is nothing to be found there.Aurore
You are correct, it turned out to be a problem with the php script. The PEAR library was not installed. I installed it on my VPS and all is well. Thanks all!Aurore
How can "please check logs" be the accepted answer to "why are my logs empty"?Cropland
I pointed the user to the default error logs not the custom error logs. Often when a script fails for some reason the error gets routed to the default error logsInternee
With PHP, I had nothing in the configured apache error logs, but found the errors with grep PHP /var/log/syslog. Probably because I had error_log = syslog in /etc/php5/apache2/php.ini.Gallic
My permissions were 775 but apache didn't like that. Changed it to 744 and it started working again. Lame.Workbook
For development it's a good idea to check /etc/php5/apache2/php.ini to make sure that display_errors and display_startup_errors are both on. There are a bunch of different settings intended to hide error messages from remote viewers for security purposes. These all need to be adjusted so that they display this information for use by a local developer.Amatol
C
169

This is an Ancient answer from 2013, back when PHP was new and security wasn't an issue:

Here in the future it's a security risk to dump errors to screen like this. You better not be doing this in any production setting.

Why are the 500 Internal Server Errors not being logged into your apache error logs?

The errors that cause your 500 Internal Server Error are coming from a PHP module. By default, PHP does NOT log these errors. Reason being you want web requests go as fast as physically possible and it's a security hazard to log errors to screen where attackers can observe them.

These instructions to enable Internal Server Error Logging are for Ubuntu 12.10 with PHP 5.3.10 and Apache/2.2.22.

Make sure PHP logging is turned on:

  1. Locate your php.ini file:

    el@apollo:~$ locate php.ini
    /etc/php5/apache2/php.ini
    
  2. Edit that file as root:

    sudo vi /etc/php5/apache2/php.ini
    
  3. Find this line in php.ini:

    display_errors = Off
    
  4. Change the above line to this:

    display_errors = On
    
  5. Lower down in the file you'll see this:

    ;display_startup_errors
    ;   Default Value: Off
    ;   Development Value: On
    ;   Production Value: Off
    
    ;error_reporting
    ;   Default Value: E_ALL & ~E_NOTICE
    ;   Development Value: E_ALL | E_STRICT
    ;   Production Value: E_ALL & ~E_DEPRECATED
    
  6. The semicolons are comments, that means the lines don't take effect. Change those lines so they look like this:

    display_startup_errors = On
    ;   Default Value: Off
    ;   Development Value: On
    ;   Production Value: Off
    
    error_reporting = E_ALL
    ;   Default Value: E_ALL & ~E_NOTICE
    ;   Development Value: E_ALL | E_STRICT
    ;   Production Value: E_ALL & ~E_DEPRECATED
    

    What this communicates to PHP is that we want to log all these errors. Warning, there will be a large performance hit, so you don't want this enabled on production because logging takes work and work takes time, time costs money.

  7. Restarting PHP and Apache should apply the change.

  8. Do what you did to cause the 500 Internal Server error again, and check the log:

    tail -f /var/log/apache2/error.log
    
  9. You should see the 500 error at the end, something like this:

    [Wed Dec 11 01:00:40 2013] [error] [client 192.168.11.11] PHP Fatal error:  
    Call to undefined function Foobar\\byob\\penguin\\alert() in /yourproject/
    your_src/symfony/Controller/MessedUpController.php on line 249
    
Clementclementas answered 11/12, 2013 at 6:20 Comment(9)
display_errors prints errors on the screen. log_errors writes errors in the log file.Empedocles
@WanLiqun It's a pretty good piece of info but it only applies to PHP, which is not even mentioned in the question.Cropland
"The errors that cause your 500 Internal Server Error are coming from a PHP module. By default, PHP does NOT log these errors." Who mentioned PHP? Server 500 Logging being disabled in PHP is an assumption and most often a wrong assumption. Apache will log server 500 errors from a faulting module (in this case php) but most often it will go to /var/log/apache2/error.log (assuming debian or similar)Internee
500 Internal Server error may refer to the .htaccess file trying to use an Apache module that isn't available! To test, disable the headers module and add this to the .htaccess file: Header add X-Custom-Header "My header content".Footway
How frustrating controller name :pKissner
This answer starts off with a bad advice to dump errors to the screen.Lovett
Why is this being upvoted and the accepted answer downvoted? when this question was asked PHP was in its infancy and PERL was the predominant language. Back then (and sometimes even now) should the interpreter crash out due to an invalid script the error would bypass the virtual hosts log and end up in the servers default log which is why the OP couldn't find the problem. Hence the answer being accepted.Internee
For me, this frustrating situation occurred because I forgot to install PHP modules that my application depended on.Decal
Down vote because this doesn't answer the question.Kashmiri
H
17

I just ran into this and it was due to a mod_authnz_ldap misconfiguration in my .htaccess file. Absolutely nothing was being logged, but I kept getting a 500 error.

If you run into this particular issue, you can change the log level of mod_authnz_ldap like so:

LogLevel warn authnz_ldap_module:debug

That will use a log level of debug for mod_authnz_ldap but warn for everything else (https://httpd.apache.org/docs/2.4/en/mod/core.html#loglevel).

Hippopotamus answered 13/5, 2013 at 20:55 Comment(3)
The question was, "How do I cause Apache to log Internal 500 errors into the error log?" This should probably be a comment.Friarbird
Good observation. I've added instructions for logging those errors.Hippopotamus
This is very useful, thank you. In my case, it was mod_proxy so LogLevel warn proxy:debug helped me track down the issue.Lacquer
A
15

Check your php error log which might be a separate file from your apache error log.

Find it by going to phpinfo() and check for error_log attribute. If it is not set. Set it: https://mcmap.net/q/159684/-where-can-i-find-error-log-files-for-php

Maybe your post_max_size is too small for what you're trying to post, or one of the other max memory settings is too low.

Austria answered 18/7, 2012 at 16:50 Comment(1)
The question was, "How do I cause Apache to log Internal 500 errors into the error log?" This should probably be a comment.Friarbird
O
12

If your Internal Server Error information doesn't show up in log files, you probably need to restart the Apache service.

I've found that Apache 2.4 (at least on Windows platform) tends to stubbornly refuse to flush log files—instead, logged data remains in memory for quite a while. It's a good idea from the performance point of view but it can be confusing when developing.

Oersted answered 22/8, 2015 at 19:17 Comment(2)
This was the correct answer for me on Linux. Even after deleting the original error.log (which was a character device file) and replacing it with a touch 777 error.log, Apache wouldn't write to it until being restarted.Monge
(╯°□°)╯︵ ┻━┻ And by restart, that means cold restart, not graceful or reload. This applies to more than php ... I just fought this with a rails/passenger server.Finding
I
8

Please Note: The original poster was not specifically asking about PHP. All the php centric answers make large assumptions not relevant to the actual question.

The default error log as opposed to the scripts error logs usually has the (more) specific error. often it will be permissions denied or even an interpreter that can't be found.

This means the fault almost always lies with your script. e.g you uploaded a perl script but didnt give it execute permissions? or perhaps it was corrupted in a linux environment if you write the script in windows and then upload it to the server without the line endings being converted you will get this error.

in perl if you forget

print "content-type: text/html\r\n\r\n";

you will get this error

There are many reasons for it. so please first check your error log and then provide some more information.

The default error log is often in /var/log/httpd/error_log or /var/log/apache2/error.log.

The reason you look at the default error logs (as indicated above) is because errors don't always get posted into the custom error log as defined in the virtual host.

Assumes linux and not necessarily perl

Internee answered 19/1, 2011 at 4:13 Comment(7)
I checked the server ErrorLog, and there is nothing to be found there.Aurore
You are correct, it turned out to be a problem with the php script. The PEAR library was not installed. I installed it on my VPS and all is well. Thanks all!Aurore
How can "please check logs" be the accepted answer to "why are my logs empty"?Cropland
I pointed the user to the default error logs not the custom error logs. Often when a script fails for some reason the error gets routed to the default error logsInternee
With PHP, I had nothing in the configured apache error logs, but found the errors with grep PHP /var/log/syslog. Probably because I had error_log = syslog in /etc/php5/apache2/php.ini.Gallic
My permissions were 775 but apache didn't like that. Changed it to 744 and it started working again. Lame.Workbook
For development it's a good idea to check /etc/php5/apache2/php.ini to make sure that display_errors and display_startup_errors are both on. There are a bunch of different settings intended to hide error messages from remote viewers for security purposes. These all need to be adjusted so that they display this information for use by a local developer.Amatol
M
4

The answers by @eric-leschinski is correct.

But there is another case if your Server API is FPM/FastCGI (Default on Centos 8 or you can check use phpinfo() function)

In this case:

  1. Run phpinfo() in a php file;
  2. Looking for Loaded Configuration File param to see where is config file for your PHP.
  3. Edit config file like @eric-leschinski 's answer.
  4. Check Server API param. If your server only use apache handle API -> restart apache. If your server use php-fpm you must restart php-fpm service

    systemctl restart php-fpm

    Check the log file in php-fpm log folder. eg /var/log/php-fpm/www-error.log

Mystic answered 28/12, 2019 at 4:1 Comment(0)
M
3

Please check if you are disable error reporting somewhere in your code.

There was a place in my code where I have disabled it, so I added the debug code after it:

require_once("inc/req.php");   <-- Error reporting is disabled here

// overwrite it
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
Molest answered 29/6, 2020 at 15:24 Comment(0)
C
2

Add HttpProtocolOptions Unsafe to your apache config file and restart the apache server. It shows the error details.

Canotas answered 16/3, 2019 at 19:16 Comment(0)
C
1

In my case it was the ErrorLog directive in httpd.conf. Just accidently noticed it already after I gave up. Decided to share the discovery ) Now I know where to find the 500-errors.

Cetus answered 16/2, 2018 at 5:40 Comment(2)
Can you please put more details in your answerAmazement
I am using Magento (CMS - Content Management System) for Apache. There was an error 500 on my page using Magento core classes. I could not find where I could see the error message. According to some answers here I tried to search in apache logs /etc/httpd/logs/error_log. But there was nothing there. Later on I found out that there is a line in my httpd.conf for that specific web host, defining the log path: <VirtualHost . ... ErrorLog /usr/www/log/error_log So I needed to look to a more specific host log not the common apache log.Cetus
T
0

Check that the version of php you're running matches your codebase. For example, your local environment may be running php 5.4 (and things run fine) and maybe you're testing your code on a new machine that has php 5.3 installed. If you are using 5.4 syntax such as [] for array() then you'll get the situation you described above.

Turgeon answered 9/4, 2013 at 19:31 Comment(1)
The question was, "How do I cause Apache to log Internal 500 errors into the error log?" This should probably be a comment.Friarbird
G
0

Try accessing a static file. If this is not working either then go to all directories from the root "/" or "c:\" to the directory of your file and check if they contain ".htaccess" files.

I once left a file in "c:\" and it had the most strange results.

Glynisglynn answered 28/5, 2016 at 4:5 Comment(1)
The question was, "How do I cause Apache to log Internal 500 errors into the error log?"Friarbird
V
0

This misconfiguration message happened for me when I used the # comment symbol in other than column 1 (remember, Apache is old software where column numbers and whitespace can sometimes be significant).

Options -Indexes # Never show folder indices

Vail answered 19/8, 2023 at 17:33 Comment(0)
B
0

Add ScriptLog logs/cgi_log[1] to your server configuration file, then you'll get Python or Bash syntax errors printed to it (and all other errors too, of course - except for PHP errors, these are controlled by a different directive).

Bik answered 28/11, 2023 at 0:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.