My Ubuntu server is configured with Apache 2.2.8 and PHP 5.2.4-2ubuntu5.18 in FastCGI mode. Everything works well, except I am seeing 500 errors that only seem to come from bots accessing the server.. for example (access.log):

x.125.71.104 - - [16/Nov/2011:10:27:39 +1100] "GET / HTTP/1.1" 500 41377 "-" "Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)"

x.40.103.239 - - [16/Nov/2011:11:05:56 +1100] "GET / HTTP/1.0" 500 14717 "-" "Mozilla/5.0 (compatible; mon.itor.us - free monitoring service; http://mon.itor.us)"

x.249.67.114 - - [14/Nov/2011:20:57:17 +1100] "GET / HTTP/1.1" 500 101 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"

x.55.39.85 - - [14/Nov/2011:19:31:06 +1100] "GET / HTTP/1.1" 500 7032 "-" "msnbot/2.0b (+http://search.msn.com/msnbot.htm)._"

It is my understanding that a 500 error will be thrown when the PHP process fails to respond to Apache, which could be caused by a fatal PHP error or if PHP runs out of processes.. so my assumption is that either the bots are hitting the server too hard, killing the PHP processes, or something in the request header from bots is causing a fatal error in my PHP script? If anyone can offer advice on this it would be greatly appreciated!



Do you want bots indexing your site? If not I wouldn't worry about it. If you do, check PHP error logs (/var/log/php is usually a good default place to look) and see what's causing PHP to trip up for bots.

They may be providing no GET params or POST data to a script which requires it to function properly. In this case I would handle the request better, possibly returning a 404 if the script is wrapping a DB query (since nothing can be found unless you provide the appropriate params). If they are doing something even stranger, maybe returning a 400 Bad Request is in order.

  • Unfortunately there is no /var/log/php file.. I'll switch the config in php.ini to log_errors = On, error_log = /var/log/php and see what I can find. Thanks! – Ryan D Nov 16 '11 at 0:54
  • No worries :) It may also be at /var/log/apache2/error.log, actually. – darvids0n Nov 16 '11 at 0:55
  • Aha, I've found a direct correlation between the 500 errors in access.log and the following error in error.log: [Wed Nov 16 14:05:59 2011] [warn] (103)Software caused connection abort: mod_fcgid: ap_pass_brigade failed in handle_request function Problem is, I have no idea how or why this error is being casued? – Ryan D Nov 16 '11 at 3:10
  • Try setting some memory-related options for FastCGI: PHP_FCGI_MAX_REQUESTS=5000 PHP_FCGI_CHILDREN=8 or similar. – darvids0n Nov 16 '11 at 3:43
  • Thanks for that. I already have PHP_FCGI_MAX_REQUESTS=5000 configured, however I have not set a value for PHP_FCGI_CHILDREN=8. Further reading suggests not setting PHP_FCGI_CHILDREN. But I have now just realised I think I may be getting confused between FastCGI and FCGID .. I'm loading LoadModule fcgid_module /usr/lib/apache2/modules/mod_fcgid.so should I be using fastcgi.so instead? – Ryan D Nov 16 '11 at 3:55

Check out this site to see if it has the information you need. http://redmine.lighttpd.net/projects/1/wiki/Docs:PerformanceFastCGI

All the way down where it says "Why is my php application returning 500 from time to time?"


For those with the 500 errors, the first line in this code needs to point to a unix socket, not a TCP/IP address / port – this is on Ubuntu 12.10.x – if you look inside /etc/php5/fpm/pool.d/www.conf you will find FPM is set up to listen to a unix socket.

FastCgiExternalServer /var/www/php5.external -socket /var/run/php5-fpm.sock
AddHandler php5-fcgi .php
AddHandler php5-fcgi .wfr
Action php5-fcgi /usr/lib/cgi-bin/php5.external
Alias /usr/lib/cgi-bin/ /var/www/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.