Laravel

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

Author: Danyal
I'm a skilled programmer specializing in Vue.js/Nuxt.js for front-end development and PHP Laravel for back-end solutions. I have a strong focus on API design and development, complemented by experience in web server setup and maintenance. My versatile expertise ensures seamless creation and maintenance of web applications, covering everything from intuitive user interfaces to robust server-side functionality. Passionate about coding and driven by a lifelong learning mindset, I invite you to explore more at danyal.dk.