500 internal server error while uploading files bigger then 100kb - mod_fcgid problem
For no special reason Drupal sites on our server (CentOS 5 with cPanel/WHM) started to make problems with file upload. Because Drupal 6/7 has use Ajax for file uploading the only thing that happens is that browser just hangs until timing out. Quick playing with different file sizes revealed that files that are less then 100kb are OK, but bigger files are creating problem. Of course php post_max_size and upload_max_filesize are set to 20mb so that was not causing problems. Strange...
Actually the biggest problem here was finding out what the hell is happening. I quickly created small html/php script with file upload form, and when testing with files bigger then 100kb I immediately got 500 internal server error - OK, that is something but still not telling much. Most annoying thing was fact that php error_log and apache logs that I was getting from Cpanel and WHM were error empty.
Yes in CentOS (managed with cPanel) you have logs all over the place. Finally founded master apache log that I needed and there was explanation
[Fri Jul 08 12:36:14 2011] [warn] [client 22.214.171.124] mod_fcgid: HTTP request length 132356 (so far) exceeds MaxRequestLen (131072), referer: http://www.montenasoft.com/.../upload.html
So MaxRequestLen from mod_fcgid (and we are running fast cgi for PHP) is limiting request length to only 130kb - If the size of the request body exceeds this amount, the request will fail with 500 Server Error.
Fix is easy you just need to add in your httpd.conf next lines
# Work around annoying fcgid limitations
# 20MB should be enough
But again when you have WHM for server management things are not that easy ;) You can not just add those lines to /etc/httpd/conf/httpd.conf because next time when you update apache or php on your server your custom httpd.conf tweaks will be lost.
Here is a correct way to do, login to WHM and go to "Apache Configuration", and then select "Include Editor"
Then in "Pre VirtualHost Include" section select "All versions" add custom MaxRequestLen configuration, and hit update.
And don't forget to restart apache on the end.
And that was it, no more 500 internal server error. Why this setting started to make problem recently is still unknown, maybe cPanel auto updates changed something silently.