WordPress async-upload.php returns 500 (Internal Server Error) after uploading a large JPG file

I’m getting an HTTP Error message when uploading a big jpg file (about 30 – 40MB) and I can see 500 Internal Server Error response in the Chrome dev tools network tab returned by the async-upload.php.

The error appears after the file is uploaded. I can see the file in the wp-content/uploads directory, so the problem is not related to the uploading process.

Read More

I suppose that the problem is related to images resizing process that happens after the file is uploaded. I tried to rebuild thumbnails manually (using several regenerate thumbnails plugins) to prove that the problem is related to the resizing process. All of them failed to resize a large image.

Things I did before posting this question:

  • I’ve increased the memory limit to 256MB in the php.ini file (memory_limit = 256M)
  • set post_max_size = 256M
  • Set up a fresh WP instance. No plugins, default theme.
  • Tested on a different machine (on VPS, same PHP settings)
  • I’ve turned off mod_security settings:

    <IfModule mod_security.c>
        SecFilterEngine Off
        SecFilterScanPOST Off
    </IfModule>
    
  • I’ve also tried to change the default image library:

    add_filter('wp_image_editors', function () {
        return ['WP_Image_Editor_GD', 'WP_Image_Editor_Imagick'];
    });
    

UPDATE:

I’ve just realised that the filter I’ve applied didn’t do anything. I have check the WP source code, and found that default value for this filter is: ['WP_Image_Editor_Imagick', 'WP_Image_Editor_GD']. I’ve changed the order, but I didn’t have Image Magic library installed, so WordPress has been using GD library anyway.

So I have installed the Image Magic PHP extension to give it try. I’ve also removed the filter because it’s default value works for me.

Replacing GD library with Image Magic solved the problem., but I’m still curious why GD library can’t handle such big images. Is there any way to solve this issue in a different way? I don’t want to be dependent on third party libraries. I would rather use a standard PHP setup (in case of deploying the site on a shared hosting where it’s not possible to install custom PHP extensions).

Related posts

4 comments

  1. If you have upgraded the PHP version. This might cause the old plugin to do so. Same thing happened with me. I upgraded php 5.6 to PHP 7 and same error had occur. When i reinstall the PHP 5.6 it started to work normally.

  2. Try this:

    In wp-config.php change this:

    define( 'WP_DEBUG', false);
    

    To

    define( 'WP_DEBUG', true );
    

    For me works!

  3. I have tried most of the thing which are possible still not working, after all, the research I have checked plugin folder disabled and checked its working for me, please disable one by one plugin and check. It’s work for me. thanks 🙂

    you can rename to the plugin folder name ( plugins to plugins_old )

    Thanks

  4. This is a Server BUG. If you dont’t change php.ini, or .htacess, try Upload a PNG file. This tricks work for me!

    enter image description here

Comments are closed.