Back to Error Center

laravel.log permission denied

Error Message

file_put_contents(): Failed opening stream: Permission denied in /storage/logs/laravel.log

Cause

The web server user (www-data, nginx, apache) doesn't have write permission to the storage/logs directory.

Solution

Fix permissions: chown -R www-data:www-data storage. Or chmod -R 775 storage. Ensure the storage directory and its subdirectories are writable.

Code Example

Fix
# Fix ownership
sudo chown -R www-data:www-data storage bootstrap/cache

# Fix permissions
sudo chmod -R 775 storage bootstrap/cache

# Add user to www-data group
sudo usermod -aG www-data $USER

# Verify permissions
ls -la storage/logs/

Debugging Steps

  1. Check file ownership with ls -la
  2. Check directory permissions
  3. Verify the web server user
  4. Check if the logs directory exists and is writable

Prevention

Set correct permissions during deployment. Include permission commands in deployment scripts. Use proper deployment tools (Forge, Envoyer).