If you have a newly installed Laravel web application or working on an already installed Laravel application. And you are facing an issue related to file and directory permissions. So in this tutorial, you will learn how to give correct file and directory permissions in laravel apps. So that errors can be resolved.
If you are facing any of the issues given below. Then it is a permission issue related to the file or directory.
- Server Error 500 when accessing Laravel
- laravel.log could not be opened?
- laravel – bootstrap/cache/cache.php, sessions.php, views.php, services.php missing
Don’t worry about how to resolve issues related to the above-given file permission and directory in laravel apps. it is explained below:
Solution 1 – Server Error 500 when accessing Laravel
After downloading laravel app, It will show server error 500 when accessing Laravel. So, you can run execute the following command on terminal:
Then, You need to adjust the permissions of storage
and bootstrap/cache
.
cd
into your Laravel project.sudo chmod -R 755 storage
sudo chmod -R 755 bootstrap/cache
Solution 2 – laravel.log could not be opened?
Laravel failed to open stream permission-denied storage, logs. In this tutorial, you will learn, how to solve storage/logs/laravel.log” could not be opened: failed to open stream: permission denied.
While you working with laravel framework and you face some errors related to laravel failing to open stream permission denied storage, laravel failed to open stream permission denied log, laravel session failed to open stream permission denied.
If you face laravel storage link permission denied. So, this tutorial will help you to give permission for linking public storage directories in Laravel app.
It turns out I was missing a view directory in laravel_root/storage/
. In order to fix this, all I had to do was:
cd {laravel_root}/storage
mkdir -pv framework/views app framework/sessions framework/cache
cd ..
chmod 777 -R storage
chown -R www-data:www-data storage
Then, You need to adjust the permissions of storage
and bootstrap/cache
.
cd
into your Laravel project.sudo chmod -R 755 storage
sudo chmod -R 755 bootstrap/cache
Solution 3 – Laravel – bootstrap/cache/cache.php, sessions.php, views.php, services.php missing
Create these directories if they don’t exist in laravel:
- storage/framework/cache
- storage/framework/sessions
- storage/framework/views
Then
- delete bootstrap/cache files
Test if it works, if not, try giving the correct permissions to the storage folder: chmod -R 775 storage/
Conclusion
In this tutorial, you have learned how to set up permission in laravel 10,9,8,7,6,5, and 4 apps.
Recommended Laravel Tutorials
If you have any questions or thoughts to share, use the comment form below to reach us.