Documentation
-
Home
-
Getting Started
-
Common Tasks
-
The Servd Plugin
-
Project Settings
-
Domains & SSL
-
Importing & Cloning
-
Assets
-
Logs
-
Plans and Billing
-
Addons
-
Team & Project Management
-
Project Security
-
Your Account
-
Troubleshooting
-
Restart Instances
-
Repair Database
-
Craft isn't installed yet
-
Speeding Up Your Project
-
My Uploaded Assets Are Disappearing
-
My Sessions Are Expiring Too Soon
-
Why Are My Environments Behaving Differently?
-
No URL found for submodule path
-
Composer and Private Repositories
-
Composer out of memory errors
-
An SSL certificate for a domain has failed to generate or renew
-
Animated GIFs Displaying Incorrectly
-
Out of memory whilst running CLI tasks
-
CloudFlare: domain already exists
-
Permission Denied Whilst Generating PDFs
-
"server reached max_children setting (5), consider raising it"
-
Missing composer "allow-plugins" config
-
Unexpected robots.txt Content
-
Why is Servd is slower than my old VPS server?
-
Error: headers already sent
-
Where's the node_modules directory?
-
-
Cookbook
-
Now & Next
-
The Small Print
Permission Denied Whilst Generating PDFs
Craft Commerce makes use of dompdf to generate invoices for your customers. In some circumstances this can result in dompdf attempting to write temporary files into the vendor folder. This is generally bad practice and on Servd results in a permissions error being thrown as the vendor folder is owned by root.
We can resolve this by telling dompdf to use Craft's storage folder for its temporary files:
Event::on(
Pdfs::class,
Pdfs::EVENT_MODIFY_RENDER_OPTIONS,
function (PdfRenderOptionsEvent $event)
{
$pathService = Craft::$app->getPath();
$dompdfRootDir = $pathService->getTempPath() . DIRECTORY_SEPARATOR . 'commerce_dompdf';
$dompdfFontDir = $pathService->getTempPath() . DIRECTORY_SEPARATOR . 'commerce_dompdf';
$event->options->setRootDir($dompdfRootDir);
$event->options->setFontDir($dompdfFontDir);
});
You can add this to a custom module's init function in your Craft project to ensure it runs with every request.