laravel-dompdf throws RuntimeException: Cannot resolve public path
Fix it fast
Most common cause, 1 of 2The project has no public folder at the project root
Publish the package config and set public_path to the folder that really holds your public files.
php artisan vendor:publish --provider="Barryvdh\DomPDF\ServiceProvider"
// config/dompdf.php
'public_path' => realpath(base_path('../public_html')),Short answer
"Cannot resolve public path" is thrown by barryvdh/laravel-dompdf 3 when realpath() fails on its base path: the dompdf.public_path setting, or base_path('public') when that setting is empty. The folder does not exist, usually because the site serves from public_html or another folder, or because a cached config holds a path from a different machine. Point dompdf.public_path at the real folder.
Which cause do you have?
Print the setting, the default it falls back to, and what realpath() makes of it. false in the last value is the error; the first two tell you which cause below applies.
php artisan tinker --execute="dump(config('dompdf.public_path'), base_path('public'), realpath(config('dompdf.public_path') ?: base_path('public')))"Then find the line you see in this list and open its fix:
- 1The project has no public folder at the project root
dompdf.public_path is null and base_path('public') names a folder that is not there, for example on shared hosting where the web root is public_html - 2A cached or copied config points public_path at a folder from another machine
dompdf.public_path holds a path from a laptop, a CI runner or an old release folder, such as C:\xampp\htdocs\app\public on a Linux server
What does the error look like?
RuntimeException: Cannot resolve public pathCannot resolve public path
Cause 1 of 2
The project has no public folder at the project root
You seedompdf.public_path is null and base_path('public') names a folder that is not there, for example on shared hosting where the web root is public_html
Check
Cannot resolve public path with an empty setting means base_path('public') does not exist. laravel-dompdf builds this path from the project root itself, not from Laravel's public_path() helper, so moving the web root, or deploying the app beside a public_html folder, leaves it pointing at nothing.
ls -ld public ../public_htmlFix
Publish the package config and set public_path to the folder that really holds your public files. If that folder sits outside the project root, check chroot as well: by default it is the project root, and dompdf opens local files only below it.
php artisan vendor:publish --provider="Barryvdh\DomPDF\ServiceProvider"
// config/dompdf.php
'public_path' => realpath(base_path('../public_html')),Verify
The last value of the first-step command is now a real path, and a PDF with a local stylesheet renders.
php artisan tinker --execute="dump(realpath(config('dompdf.public_path')))"Confirmed by github.com
Cause 2 of 2
A cached or copied config points public_path at a folder from another machine
You seedompdf.public_path holds a path from a laptop, a CI runner or an old release folder, such as C:\xampp\htdocs\app\public on a Linux server
Check
Cannot resolve public path with a filled-in setting means that exact folder is missing here. php artisan config:cache runs the config files once and stores the resulting values, so a cache built on another machine or in an old release directory keeps that machine's absolute paths.
ls -l bootstrap/cache/config.php && grep -o "'public_path' => '[^']*'" bootstrap/cache/config.phpFix
Clear the cached config, then build it again on the server itself as part of the deploy.
php artisan config:clear
php artisan config:cacheVerify
grep the new cache: public_path now shows the server's own folder, and generating the PDF works.
grep -o "'public_path' => '[^']*'" bootstrap/cache/config.phpConfirmed by laravel.com
How do I stop it coming back?
- Set dompdf.public_path explicitly in config/dompdf.php on any host whose web root is not the project's public folder.
- Run config:cache on the server during each deploy, never on a build machine whose paths differ.
- Keep one smoke test that renders a small PDF with a local image after every deploy.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine on the same stack: Spotless Laundry, EZ Estimater.