I can't initialize DomPDF. I am using Debian 11, Apache2, PHP8.1, and DomPDF 2.0.
The following code works fine on my locally installed XAMPP Apache2 Server, but when I try to execute it on the Debian Server I am getting a 500 Internal Server Error. What's also weird is that I don't get an Exception Message, but I am using a try-catch.
Code:
<?php
try {
require_once("dompdf/autoload.inc.php");
} catch(Exception $ex) {
echo "Requiring failed.";
die();
}
use Dompdf\DOMPDF;
set_time_limit(300);
try {
echo "1";
$dompdf = new DOMPDF();
echo "2";
$dompdf->getOptions()->setChroot(realpath(__DIR__ . "/../"));
$dompdf->set_base_path(realpath(__DIR__));
} catch(Exception $ex) {
echo "Failure!";
die();
}
?>
As an output, I get "1" and then an Internal Server Error, but I am expecting either "12" as an output or "1Failure!".
Any ideas?
EDIT: I found the Problem in the Server Logs (thanks to Mark). It said that "Dompdf\DOMPDF" could not be found. I changed the use to use Dompdf\Dompdf; and now it's working.