zu Navigation
15 Jul, 2011

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 91.182.145.210] 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
</IfModule>

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

Kommentare

Saved!

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

Thank you so much

Thank you so much

Lifesaver!

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

Joomla/K2

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)

Thank you!

Thanks, you made my day!

Thank You :)

Thank YOU :)

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Internal paths in single or double quotes, written as "internal:node/99", for example, are replaced with the appropriate absolute URL or path. Paths to files in single or double quotes, written as "files:somefile.ext", for example, are replaced with the appropriate URL that can be used to download the file.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd><br><p>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.