'MPDF always gives 500 Internal Server Error

I've looked at multiple tutorials on the matter and apparently MPDF is a simple as can be.

<?php 
  require_once('tools/mpdf.php');
  $mpdf = new mPDF();
  $mpdf->WriteHTML('<p>Your first taste of creating PDF from HTML</p>');

  $mpdf->Output();
  exit;
?>

Obviously I'm going to build on top of this but I can't even get the basics working for some reason. All I get is a "500 Internal Server Error". I've stripped the file down to just

<?php 
  require_once('tools/mpdf.php');
?>

And I get that error. I've ensured that the mpdf.php file is in the tools directory and properly loaded onto my server, so there's no issue there..

Any ideas?



Solution 1:[1]

I was having this issue and found a simple solution. Mpdf worked well on my local machine but I had the trouble when using it on a remote server.

If anyone else is having the same issue, when deploying your app on a remote server.

  1. Check your server error log,
  2. If you see an error like this "Exceptioncaught Mpdf\MpdfException: Temporary files directory.... is not writeable"
  3. You may try to change the permission of the mpdf/tmp folder example: chmod 777 /vendor/mpdf/mpdf/tmp
    1. Also check the owner of the directory, assign it to your webserver if you are using apache example: chown www:www /vendor/mpdf/mpdf/tmp

It worked for me, hope it can help others...

Solution 2:[2]

I had the same problem, I was desperate in the end but I deleted tmp sub-folder from mpdf folder and it started working.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Jose lepcha