Laravel says the bootstrap/cache directory must be present and writable
The /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.
Fix it fast
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"));'2Match what you see, then jump to its fix
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/cache2Fix
Create it. Laravel needs to write to bootstrap/cache and storage.
mkdir -p bootstrap/cache3Verify
Rebuild the package manifest.
php artisan package:discoverConfirmed by raw.githubusercontent.com
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 -u2Fix
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 storage3Verify
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
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 fixBack end
composer install fails at php artisan package:discover with error code 255
Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 255
Code 255 is only the exit code of a PHP crash inside artisan.
3 causes, each with a fixBack end
Composer says the gd extension is missing on a Laravel project
composer install or composer update stops on a package that requires ext-gd
Composer refuses to install a package that requires ext-gd when the PHP binary running Composer has no GD extension.
4 causes, each with a fixBack 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 fixBack end
Intervention Image will not save the file in a Laravel app
Can't write image data to path (/var/www/app/public/uploads/photo.jpg)
Intervention Image writes straight to a file path.
3 causes, each with a fixBack end
Laravel file upload returns 413 behind nginx
413 Content Too Large
A 413 means a limit refused the request body before Laravel could use it.
3 causes, each with a fix