Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Node.js, PHP and APIs

laravel-dompdf throws RuntimeException: Cannot resolve public path

Your error

RuntimeException: Cannot resolve public path1 more line it can show

Fix it fast

Most common cause, 1 of 2

The 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.

Fix
php artisan vendor:publish --provider="Barryvdh\DomPDF\ServiceProvider"

// config/dompdf.php
'public_path' => realpath(base_path('../public_html')),
Did this fix it?
Full steps for this cause: check, fix, verify

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.

  • Applies to barryvdh/laravel-dompdf 3.1, dompdf 3.1, Laravel 13
  • Updated
  • By Maaz Zindani, Senior Software Engineer

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.

Run this first
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:

  1. 1The project has no public folder at the project rootdompdf.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
  2. 2A cached or copied config points public_path at a folder from another machinedompdf.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 path
  • Cannot 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.

Check
ls -ld public ../public_html

Fix

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.

Fix
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.

Verify
php artisan tinker --execute="dump(realpath(config('dompdf.public_path')))"

Confirmed by github.com

Did this fix it?

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.

Check
ls -l bootstrap/cache/config.php && grep -o "'public_path' => '[^']*'" bootstrap/cache/config.php

Fix

Clear the cached config, then build it again on the server itself as part of the deploy.

Fix
php artisan config:clear
php artisan config:cache

Verify

grep the new cache: public_path now shows the server's own folder, and generating the PDF works.

Verify
grep -o "'public_path' => '[^']*'" bootstrap/cache/config.php

Confirmed by laravel.com

Did this fix it?

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.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.