Laravel error Failed to open stream: Permission denied

I don’t remember acutally if I faced this issue while runing my Laravel 5.6 app in Homestead or not. But as I deployed app to the staging and production with DigitalOcean after running composer install, preparing .env for production and clearing cache. When I opened my app in browser got following error:

FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught ErrorException: file_put_contents(/var/www/app/storage/framework/views/....php): failed to open stream: Permission denied in ... vendor/laravel/framework/src/Illuminate/Filesystem/Files

This only happens when app is set for other than local, test environment.
APP_ENV=(local to production)

This permission issue can be resolved by running following command.

sudo chown -R www-data:www-data storage

About the author

Danyal Ali Butt

I'm working as programmer since 2002. Born, grew up, studied and worked in Pakistan now Im located in Denmark since 2006.

View all posts