In this tutorial you will learn about the How to Set Up File Permissions in Laravel 8 and its application with practical example.
In this How to Set Up File Permissions in Laravel 8 tutorial I will show you how to set file permission or directory permission in laravel 8 application. In this tutorial you will learn to set file permission in laravel, you will also learn to set directory permission in laravel 8.
When we create a new laravel 8 application we may encounter some errors related due to file permission in laravel. Below is list of some of common issues we may encounter:
- How to fix Error: laravel.log could not be opened Permission denied?
- How to set up file permissions for Laravel?
- Laravel – bootstrap/cache/services.php missing
- Laravel – bootstrap/cache directory must be present and writable
- Laravel – bootstrap/frameworks/sessions.php, views.php, services.php missing
- failed to clear cache. make sure you have the appropriate permissions
How to Set Up File Permissions in Laravel 8
In this step by step tutorial I will help you to fix some of common issues related to files permission in laravel.
Step 1 – Install Laravel 8 App
First of all we need to create a fresh laravel project, download and install Laravel 8 using the below command
1 |
composer create-project --prefer-dist laravel/laravel blog |
Step 2 – Start Development Server
Now, lets start the development server using following artisan command –
1 |
php artisan serve |
Now, open the following URL in browser to see the output –
1 |
URL : http://localhost:8000/blog |
Solution 1 – Server Error 500 when accessing Laravel 8 (Solve)
After fresh laravel 8 installation we get server error 500 when we accessing project root . So, you can try to run the following command on terminal. You may also need to adjust the permissions of storage
and bootstrap/cache
.
1 2 3 |
cd into your Laravel project. sudo chmod -R 755 storage sudo chmod -R 755 bootstrap/cache |
Solution 2 – laravel.log could not be opened?
If you now face Laravel failed to open stream permission denied storage error. Now I will show you how to solve storage/logs/laravel.log” could not be opened: failed to open stream: permission denied. It turns out I was missing a view directories in laravel_root/storage/
. In order to fix this, all I had to do was:
1 2 3 4 5 |
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
.
1 2 3 |
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:
1 2 3 |
storage/framework/cache storage/framework/sessions storage/framework/views |
Then
1 |
delete bootstrap/cache files |
Try to set correct permissions to the storage folder: chmod -R 775 storage/