I started to get a nasty error on the production server that seems to be related to open_basedir restriction but that seems to have no legitimate cause.
The error is triggered on line 3361 of the file dompdf/dompdf/lib/Cpdf.php:
if (!isset($this->fonts[$font]) && file_exists($dir . $metrics_name)) {
The error message is this:
ErrorException
file_exists(): open_basedir restriction in effect. File(/.ufm) is not within the allowed path(s): (/home/username/:/tmp:/usr/share/pear)
I have googled about it and found that it means that dompdf cannot access the file in question because it is outside of the allowed paths. But it is not so in my case.
If i run
$dompdf = new \Dompdf\Dompdf();
$options = new \Dompdf\Options();
var_dump($dompdf->getOptions($options)); exit;
I get the options object:
object(Dompdf\Options)#222 (27) {
["rootDir":"Dompdf\Options":private]=>
string(71) "/home/username/domains/domainname.lt/mpkiktesting/vendor/dompdf/dompdf"
["tempDir":"Dompdf\Options":private]=>
string(4) "/tmp"
["fontDir":"Dompdf\Options":private]=>
string(81) "/home/username/domains/domainname.lt/mpkiktesting/vendor/dompdf/dompdf/lib/fonts"
["fontCache":"Dompdf\Options":private]=>
string(81) "/home/username/domains/domainname.lt/mpkiktesting/vendor/dompdf/dompdf/lib/fonts"
["chroot":"Dompdf\Options":private]=>
array(1) {
[0]=>
string(71) "/home/username/domains/domainname.lt/mpkiktesting/vendor/dompdf/dompdf"
}
["logOutputFile":"Dompdf\Options":private]=>
string(12) "/tmp/log.htm"
["defaultMediaType":"Dompdf\Options":private]=>
string(6) "screen"
["defaultPaperSize":"Dompdf\Options":private]=>
string(6) "letter"
["defaultPaperOrientation":"Dompdf\Options":private]=>
string(8) "portrait"
["defaultFont":"Dompdf\Options":private]=>
string(5) "serif"
["dpi":"Dompdf\Options":private]=>
int(96)
["fontHeightRatio":"Dompdf\Options":private]=>
float(1.1)
["isPhpEnabled":"Dompdf\Options":private]=>
bool(false)
["isRemoteEnabled":"Dompdf\Options":private]=>
bool(false)
["isJavascriptEnabled":"Dompdf\Options":private]=>
bool(true)
["isHtml5ParserEnabled":"Dompdf\Options":private]=>
bool(false)
["isFontSubsettingEnabled":"Dompdf\Options":private]=>
bool(true)
["debugPng":"Dompdf\Options":private]=>
bool(false)
["debugKeepTemp":"Dompdf\Options":private]=>
bool(false)
["debugCss":"Dompdf\Options":private]=>
bool(false)
["debugLayout":"Dompdf\Options":private]=>
bool(false)
["debugLayoutLines":"Dompdf\Options":private]=>
bool(true)
["debugLayoutBlocks":"Dompdf\Options":private]=>
bool(true)
["debugLayoutInline":"Dompdf\Options":private]=>
bool(true)
["debugLayoutPaddingBox":"Dompdf\Options":private]=>
bool(true)
["pdfBackend":"Dompdf\Options":private]=>
string(4) "CPDF"
["pdflibLicense":"Dompdf\Options":private]=>
string(0) ""
You can see that all the right paths set, either in /tmp or /home/username, despite what the error message says. Tried changing tempDir to a path within /home/username/, but it did not help:.
Here is the code that generates the pdf:
$html = view('common/pdf_header_view') . view('calls_month_report_view', $this->data) . view('common/pdf_footer_view');
$dompdf = new \Dompdf\Dompdf();
$options = new \Dompdf\Options();
// commenting this line out makes the error go away
$options->set('isPhpEnabled', true);
$options->set('defaultFont', 'Helvetica');
$dompdf->setOptions($options);
$dompdf->loadHtml($html);
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
$dompdf->stream("SC-ataskaita-" . $period . ".pdf");
and here is the resulting content of $html variable:
<!doctype html>
<html lang="lt">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>KĮC MPKIK sistema - pdf</title>
<link rel="stylesheet" href="/?url=https%3A%2F%2Fdomainname.lt%2Fsistematesting%2Fcss%2Fstyles.css">
<style type="text/css">
* {
margin: 0;
padding: 0;
}
body {
font-size: 11px;
font-family: 'DejaVu Sans';
margin-left: 100px;
margin-top: 60px;
margin-right: 50px;
margin-bottom: 70px;
}
#page-wrap {
width: 600px;
margin: 0 auto;
}
</style>
</head>
<body>
<script type="text/php">
if (isset($pdf))
{
$x = 785;
$y = 560;
$text = "{PAGE_NUM} / {PAGE_COUNT}";
$font = $fontMetrics->get_font("dejavu", "normal");
$size = 8;
$color = array(0,0,0);
$word_space = 0.0;
$char_space = 0.0;
$angle = 0.0;
$pdf->page_text($x, $y, $text, $font, $size, $color, $word_space, $char_space, $angle);
}
</script>
<p>Some pretty basic html as content, will not bother you with it.</p>
</body>
</html>
Now, I have zeroed in on the code and found that if I comment out the line $options->set('isPhpEnabled', true); the problem goes away. So the code that triggers the error must be somewhere in the contents of html, the code that should insert the page numbers (which it used to do, but which it no longer does on my development system with $options->set('isPhpEnabled', true);, which does not have the open_basedir restriction and so no error is triggered...
I am quite sure that even though my code might not be the best quality it should not result in the dompdf (or rather the Cpdf lib) trying to access some file outside of directories allowed by open_basedir. So there must be a bug somewhere...
But if anyone could help me find a workaround that would bring back my page numbers, I would be grateful...
I started to get a nasty error on the production server that seems to be related to open_basedir restriction but that seems to have no legitimate cause.
The error is triggered on line 3361 of the file dompdf/dompdf/lib/Cpdf.php:
if (!isset($this->fonts[$font]) && file_exists($dir . $metrics_name)) {The error message is this:
I have googled about it and found that it means that dompdf cannot access the file in question because it is outside of the allowed paths. But it is not so in my case.
If i run
I get the options object:
You can see that all the right paths set, either in /tmp or /home/username, despite what the error message says. Tried changing tempDir to a path within /home/username/, but it did not help:.
Here is the code that generates the pdf:
and here is the resulting content of $html variable:
Now, I have zeroed in on the code and found that if I comment out the line
$options->set('isPhpEnabled', true);the problem goes away. So the code that triggers the error must be somewhere in the contents of html, the code that should insert the page numbers (which it used to do, but which it no longer does on my development system with$options->set('isPhpEnabled', true);, which does not have the open_basedir restriction and so no error is triggered...I am quite sure that even though my code might not be the best quality it should not result in the dompdf (or rather the Cpdf lib) trying to access some file outside of directories allowed by open_basedir. So there must be a bug somewhere...
But if anyone could help me find a workaround that would bring back my page numbers, I would be grateful...