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 /storage
directory 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.
![](https://bettersnippets.com/btrsnpt-child-theme/shortcodes/we-recommend/images/down-arrow@1.webp)
Article continues below
![](https://bettersnippets.com/btrsnpt-child-theme/shortcodes/we-recommend/images/kinsta-logo-light@2.webp)
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.
- Cloudflare integration
- Automatic daily backups
- DDoS protection
- Exclusively for WordPress
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