0
0
LaravelDebug / FixBeginner · 3 min read

Fix Permission Denied Storage Error in Laravel Quickly

To fix permission denied errors in Laravel storage, set the correct permissions on the storage and bootstrap/cache directories using chmod -R 775 storage bootstrap/cache and ensure the web server user owns these folders with chown -R www-data:www-data storage bootstrap/cache. This allows Laravel to write files without permission issues.
🔍

Why This Happens

Laravel needs to write files like logs, cache, and uploads inside the storage and bootstrap/cache directories. If these folders do not have the right permissions or ownership, the web server cannot write to them, causing a permission denied error.

php
// Trying to write a log file without proper permissions
Log::info('Test log entry');
Output
file_put_contents(/path/to/project/storage/logs/laravel.log): failed to open stream: Permission denied
🔧

The Fix

Change the permissions of the storage and bootstrap/cache folders to allow the web server to write files. Also, set the ownership to the web server user (commonly www-data on Ubuntu). This ensures Laravel can create and modify files without errors.

bash
sudo chown -R www-data:www-data storage bootstrap/cache
sudo chmod -R 775 storage bootstrap/cache
Output
No output on success; permissions updated
🛡️

Prevention

Always set correct permissions and ownership after deploying or cloning your Laravel project. Use deployment scripts to automate this. Avoid giving overly broad permissions like 777 as it is insecure. Regularly check permissions if you move your project to a new server or environment.

⚠️

Related Errors

Other common permission errors include:

  • 403 Forbidden when the web server cannot access files.
  • Failed to write cache due to incorrect bootstrap/cache permissions.
  • Upload errors when storage/app/public is not writable.

Fix these by applying similar permission and ownership changes.

Key Takeaways

Set correct ownership of storage folders to the web server user with chown.
Use chmod 775 on storage and bootstrap/cache to allow write access safely.
Avoid using chmod 777 as it poses security risks.
Automate permission fixes in deployment scripts to prevent errors.
Check permissions after moving or cloning your Laravel project.