Maaz Zindani

Loading the index…

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

Laravel says the bootstrap/cache directory must be present and writable

ErrorThe /var/www/app/bootstrap/cache directory must be present and writable.

Short answer

Laravel writes its package manifest into bootstrap/cache and throws when that folder is missing or the current user cannot write to it. Create the folder if it is gone, then give the user that runs PHP write access. Composer scripts and the web server may run as different users, so check both.

  • Applies to Laravel 12, PHP 8.3, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Check that the folder exists, who owns it, and whether the user running the failing command can write there.

    ls -ld bootstrap/cache
    id -un
    php -r 'var_dump(is_writable("bootstrap/cache"));'
  2. 2Match what you see, then jump to its fix

    1. 1ls: cannot access 'bootstrap/cache': No such file or directoryThe directory does not existFix
    2. 2is_writable prints bool(false) and ls shows an owner that is not youThe folder belongs to another user than the one running the commandFix

What does the error look like?

  • The /var/www/app/bootstrap/cache directory must be present and writable.

Cause 1 of 2

The directory does not exist

1Check

Laravel's check is a single is_writable() on the folder, so a missing folder gives the same message as a locked one.

ls -ld bootstrap bootstrap/cache

2Fix

Create it. Laravel needs to write to bootstrap/cache and storage.

mkdir -p bootstrap/cache

3Verify

Rebuild the package manifest.

php artisan package:discover

Confirmed by raw.githubusercontent.com

Did this fix it?

Cause 2 of 2

The folder belongs to another user than the one running the command

1Check

The deployment guide says the web server process owner needs write access to bootstrap/cache and storage. A folder created by root, or by a deploy user, blocks everyone else.

ls -ld bootstrap/cache storage
ps -o user= -C php-fpm8.3 | sort -u

2Fix

Give the folder to the user that runs PHP and keep your own user in the group. Use the PHP-FPM user from the check above in place of www-data if it differs.

sudo chown -R "$USER":www-data bootstrap/cache storage
sudo chmod -R ug+rwX bootstrap/cache storage

3Verify

Run the command that failed, then as the web user.

php artisan package:discover
sudo -u www-data php -r 'var_dump(is_writable("bootstrap/cache"));'

Confirmed by laravel.com

Did this fix it?

How do I stop it coming back?

  • Run composer and artisan as the same user on the server, or keep a shared group with write access.
  • Set permissions once in the deploy script after the new release is unpacked.
  • Do not run composer install as root on a server unless you reset ownership afterwards.

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 built on the same technologies:

Related fixes

Back end

Laravel cannot write its log file or the storage folder

The stream or file "/var/www/app/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied

The user that runs PHP (php-fpm or Apache, often www-data) cannot write to storage or bootstrap/cache.

4 causes, each with a fix

Back end

Why a Filament panel feels slow on a Laravel server

The panel is fast on a small demo and slow once there are many resources, pages and widgets

A slow Filament panel on a server is most often running without the production caches.

3 causes, each with a fix

Next step

Want this handled for good?

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