Congratulations! you were able to install a fresh Laravel environment; But immediately after firing up your PHP server, you open the app on the browser, only to get the following exception:

ErrorException failed to open stream: Permission denied

This is pretty much a common situation that normally affects the /storagedirectory and quite frankly not a serious issue.

The /storage directory contains logs, compiled Blade templates, file based sessions, file caches, among other files generated by Laravel. When the app does not have the permission to read or write to the /storage directory, you will get the Laravel failed to open stream error. [*]

Solution

Access your Laravel installation from the command line to make sure the server is set as the owner of the /storage files. If not:

  • Identify the user and group that it (the server) belongs to and assign them to the storage directory.
  • Change permissions on the /storage directory so it can be read and written by users and owners.

Article continues below

Our Sponsored Pick
| TrustScore 4.6

So I know our tutorials are totally awesome 😉. But maybe, going through how-to's is not how you would like to be spending your precious time. Imagine a world where things just work. Kinsta's hosting platform gets our official -"Easy Way of the Day" seal. Advanced features that are incredibly easy to set up.

Pros:
  • Cloudflare integration
  • Automatic daily backups
  • DDoS protection
Cons:
  • Exclusively for WordPress
Explore Platform Read Reviews
We earn a commission if you click this link and make a purchase at no additional cost to you.
07/27/2024 6:44 am UTC

To do so run the following command to the /storage folder using the terminal. Do this while inside the root directory of the Laravel installation:

chown -R www-data:www-data storage/

Make sure that your server works under the www-data user/group. This can be different under other systems.

For most of my mac setups it would be something like _www; For linux setups it would be something like the snippet above.

The next and final step is to give owners and groups the ability to read and write recursively throughout the directory.

While we are still in the root directory of our installation, perform the following on your command line:

chmod -R 777 storage/

Fire your PHP server again and head back to the browser. If the issue was permission based and related to the /storage directory, you should now be good to go.

If the problem persists, read the error message and identify what directory the server cannot access. Proceed to change the permissions.

Footnotes