Marc Bosse
Marc Bosse

Reputation: 70

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?

Upvotes: 4

Views: 8363

Answers (2)

Donda
Donda

Reputation: 71

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, which I do not recommend because it would give read, write and execute permission to the owner, group and public
  4. The best approach is to check the owner of the directory and assign it to your web server if you are using apache, example: chown www:www /vendor/mpdf/mpdf/tmp

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

Upvotes: 7

Jose lepcha
Jose lepcha

Reputation: 1

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

Upvotes: 0

Related Questions