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] 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
<IfModule mod_fcgid.c>
  # 20MB should be enough
  MaxRequestLen 20000000

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"

WHM httpd configuration - selcting include editor

Then in "Pre VirtualHost Include" section select "All versions" add custom MaxRequestLen configuration, and hit update.

adding custom configuration in 'Pre VirtualHost Include' section

And don't forget to restart apache on the end.

don't forget to restart apache

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.

Read original article

Add a new comment


You saved my day! Thanks a lot for this beautiful explanation! And I was wondering why this happened suddenly...

Thank you so much

New VPS with WHM, worked fine until I upgraded my PHP and rebuilt Apache to run PHP on FastCGI instead of suPHP and gzip support, etc.
Site was running way faster, but suddenly, image uploads were broken! This post saved my life. I wouldn't have ever thought to look here.
Brohoof, sir. :)

Had a client with Joomla/K2, upload of files wasn't working, tests showed that 100kb files went through, but not much larger than that, developers had it working on the test server, client was going mad, thankfully found this page. A 1&1 server with CentOs and Plesk control panel. I believe Plesk does the configuration. All good now (until Plesk overwrites it again, I guess)

Thanks, you made my day!

Thank YOU :)

I spent 4 hours trying to find the source of this problem, it didn't work exactly like this in my case, I had to edit a fcgi.conf file under /etc/httpd
Using Plesk panel 11 and initial limit was 16MB

After hours and hours, looking at file and dir permissions,
and looking at all kind of file-size-settings and time-outs,

your solution did the job !!!!!!

Many thnx your made my day, really !!


for Marketers

Integrate multi-channel Digital Experience (DX) & communities with commerce experience

for Business

Use web, mobile and social to improve your products and services

for Government

Improve efficiency & lower costs with our consultancy & development

for Education

Reduce costs & engage education community while preserving legacy solutions