Laravel failed to open stream: Permission denied - Rocketeers app

  [ Rocketeers ](/)   

[Login](https://rocketeersapp.com/login) 

 On this page

 Knowledge
---------

Laravel failed to open stream: Permission denied
================================================

### [\#Laravel](https://rocketeersapp.com/knowledge/laravel)

A blank page or 500 error right after deploying is almost always a permission problem on the storage or bootstrap/cache directory. Here is how to fix the ownership properly.

 Published by [Mark van Eijk](https://rocketeersapp.com/author/mark-van-eijk) on June 23, 2026 · 1 minute read

1. [About the error](#content-about-the-error)
2. [Why do I see this error](#content-why-do-i-see-this-error)
3. [Solution](#content-solution)
4. [A few warnings](#content-a-few-warnings)

[\#](#content-about-the-error "Permalink")About the error
---------------------------------------------------------

You'll find a line like this in your log, or on screen with debug enabled:

 ```
file_put_contents(/var/www/storage/logs/laravel.log): Failed to open stream: Permission denied

```

The path varies, it might be `storage/framework/views`, `storage/framework/cache`, or `bootstrap/cache`, but the cause is always the same: PHP tried to write a file and the operating system said no.

[\#](#content-why-do-i-see-this-error "Permalink")Why do I see this error
-------------------------------------------------------------------------

Laravel needs to write to a few directories while it runs: logs, compiled Blade views, the framework cache and the config/route cache. If the user running PHP-FPM (usually `www-data`) does not own those directories, every write fails.

This bites most often right after a deploy or a `git clone`, because the files were created by your own user (or by root), not by the web server user. The daily log channel is a common trigger: whichever process writes the first log line of the day owns that file, and the other process then can't append to it.

[\#](#content-solution "Permalink")Solution
-------------------------------------------

Give ownership of the writable directories to the web server user and set sensible permissions:

 ```
sudo chown -R www-data:www-data /var/www/storage /var/www/bootstrap/cache
sudo chmod -R 775 /var/www/storage /var/www/bootstrap/cache

```

Replace `www-data` with `nginx` on RHEL/CentOS based systems, and adjust the path to your project root.

If your deploy user and the web server user are different, add your deploy user to the web server group so both can write:

 ```
sudo usermod -aG www-data deployer

```

After fixing permissions, clear any half-written cache files:

 ```
php artisan optimize:clear

```

See [clearing the cache in Laravel](/clear-cache-laravel) for what that command does.

### [\#](#content-a-few-warnings "Permalink")A few warnings

- **Never use `chmod 777`.** It lets any user on the server write to your application files, which is a real security risk. `775` with the correct group ownership is enough.
- On **RHEL, CentOS or Fedora with SELinux** in enforcing mode, correct Unix permissions still aren't enough. You also need the right SELinux context:

 ```
sudo chcon -R -t httpd_sys_rw_content_t /var/www/storage /var/www/bootstrap/cache

```

With debug off, this error reaches visitors as a generic [500 Internal Server Error](/500-internal-server-error-laravel). The same kind of permission problem on the web root itself (rather than `storage`) instead produces a [403 Forbidden in nginx](/403-forbidden-nginx).

### Subscribe to our newsletter

Do you want to receive regular updates with fresh and exclusive content to learn more about web development, hosting, security and performance? Subscribe now!

  Fill in your email address to receive updates  Subscribe 

#### More in [\#Laravel](https://rocketeersapp.com/knowledge/laravel)

- [How to use different PHP versions with Laravel Valet](https://rocketeersapp.com/knowledge/different-php-versions-laravel-valet)
- [Disable cookies in Laravel](https://rocketeersapp.com/knowledge/disable-cookies-in-laravel)
- [Logging in Laravel](https://rocketeersapp.com/knowledge/laravel-logging)
- [How to check which Laravel version of your app is using](https://rocketeersapp.com/knowledge/check-laravel-version)
- [Disable CSRF in Laravel](https://rocketeersapp.com/knowledge/disable-csrf-in-laravel)
- [Creating an encrypted cookie value in Laravel](https://rocketeersapp.com/knowledge/creating-an-encrypted-cookie-value-in-laravel)

 [View all 19 articles →](https://rocketeersapp.com/knowledge/laravel)
