• Please complete the contact form below with details about your inquiry and I'll get back to you as soon as possible.

  • This field is for validation purposes and should be left unchanged.

500 Server error when uploading a PDF file in WordPress

Just had to deal with an obscure issue, that I believe is more common to happen on a shared hosting. So uploading a PDF file in WordPress, would fail to a 500 server error page. Server logs show nothing, just some information about some ‘Ghostscript GPL’ and some ‘broken headers’. So I had to debug the application the usual way and found it was failing in /wp-includes/media.php on line 2909:

$implementation = _wp_image_editor_choose( $args );

if ( $implementation ) {
    $editor = new $implementation( $path );
    $loaded = $editor->load(); //this line

    if ( is_wp_error( $loaded ) )
      return $loaded;

return $editor;
}

Dumping the $implementation variable, I found it was the name of an image processing library wrapper WP_Image_Editor_Imagick . Image processing libraries can be extremely memory demanding, especially when they have to deal with a PDF file. Why WordPress needs to process a PDF file with Imagick, I don’t know. But I got to solve this server error by increasing the PHP max memory directive. There’s not specific value that will work in your case, just test in increments of 32Mb blocks and be generous if your server allows.

If you found this helpful, let me know in the commentary section below 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *