MPDF always gives 500 Internal Server Error
mpdf
Solution
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.
- Check your server error log
- If you see an error like this `"Exceptioncaught Mpdf\\MpdfException: Temporary files directory.... is not writeable"`
- 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
- 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.
Problem
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?