Laravel cannot find or create its storage folders (sessions, logs)
file_put_contents(/var/www/app/storage/framework/sessions/Zk3...): Failed to open stream: No such file or directoryShort answer
Laravel writes sessions, views, cache and logs into subfolders of storage. If one of them is missing, or the web user may not create it, you get file_put_contents failed to open stream: No such file or directory, or Monolog's 'no existing directory' error. Recreate the folders, make storage writable, or move sessions off disk.
Fix it fast
1Find out which cause you have
Check which of the stock storage folders exist and who owns them.
ls -ld storage storage/framework/* storage/logs2Match what you see, then jump to its fix
- 1
ls reports No such file or directory for storage/framework/sessions, cache, views or storage/logs.A stock folder is missingFix - 2
The folders exist, but the error still says it could not be created, or sessions never appear.The web server user may not write to storageFix - 3
SESSION_DRIVER=file in .env, on a host with a read-only or shared disk.Sessions do not have to live on diskFix
- 1
What does the error look like?
file_put_contents(/var/www/app/storage/framework/sessions/Zk3...): Failed to open stream: No such file or directoryThere is no existing directory at "/var/www/app/storage/logs" and it could not be created:
Cause 1 of 3
A stock folder is missing
1Check
A fresh Laravel project has storage/framework with the folders cache, sessions, testing and views, plus storage/app and storage/logs. A folder that did not come across when the project was copied or deployed is gone.
ls -d storage/app storage/logs storage/framework/cache storage/framework/sessions storage/framework/views2Fix
Recreate the missing folders.
mkdir -p storage/app storage/logs
mkdir -p storage/framework/cache storage/framework/sessions storage/framework/testing storage/framework/views3Verify
Load a page that starts a session, then list the sessions folder.
ls storage/framework/sessions | headConfirmed by laravel.com
Cause 2 of 3
The web server user may not write to storage
1Check
Laravel needs write access to storage and bootstrap/cache for the user that runs the web server.
ps -o user= -C php-fpm8.3 | sort -u && ls -ld storage bootstrap/cache2Fix
Give that user write access to both folders. On Debian and Ubuntu the user is usually www-data.
sudo chown -R www-data:www-data storage bootstrap/cache
sudo chmod -R ug+rwX storage bootstrap/cache3Verify
Create a test file as the web user.
sudo -u www-data touch storage/framework/sessions/.write-test && echo okConfirmed by laravel.com
Cause 3 of 3
Sessions do not have to live on disk
1Check
The file driver stores sessions in storage/framework/sessions. Other drivers do not touch that folder.
grep SESSION_DRIVER .env2Fix
Switch to the database driver, create the sessions table, and clear the cached config.
# .env
SESSION_DRIVER=database
php artisan make:session-table
php artisan migrate
php artisan config:clear3Verify
Log in, then count rows in the sessions table.
php artisan tinker --execute="echo DB::table('sessions')->count();"Confirmed by laravel.com
How do I stop it coming back?
- Run mkdir -p for the storage folders in your deploy script, before the first request.
- Run artisan commands as the same user as the web server, or fix ownership at the end of the deploy.
- On servers with a read-only app folder, send sessions and logs to a database or stderr instead of files.
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 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 fixBack end
Laravel says the bootstrap/cache directory must be present and writable
The /var/www/app/bootstrap/cache directory must be present and writable.
Laravel writes its package manifest into bootstrap/cache and throws when that folder is missing or the current user cannot write to it.
2 causes, each with a fix