Failed to open stream: Permission denied in Laravel


#1

When browsing your laravel project in the browser using localhost, you may get an error in the exception handler. URL could be like http://localhost/laravel/public

The stream or file /app/storage/logs/laravel.log could not be opened. Permission denied in /bootstrap/compiled.php. Changing the permissions of storage/ will give you the following error.

file_put_contents(meta/services.json): failed to open stream. Permission denied.

Solution

Basically, it is a permission issue. We have to run chmod recursively on the storage directory. We have to change permissions as well as regenerate the composer autoload files.

Run the following commands for Laravel version 5.4 and above

php artisan cache:clear
chmod -R 777 storage/
composer dump-autoload

For Laravel version below 5.4, Run the following commands.

php artisan cache:clear
chmod -R 777 app/storage/
composer dump-autoload

It will resolve your issue.