I have a problem since I upgraded to laravel 9. When I upload an image to storage, the permissions to access the file are no longer correct.
Example : A user uploads a new image: the image save to this path: storage/app/public/folder/{user_id}/{project_name}/photos/my_photo.jpg
my_photo.jpg has the correct permissions (644)
but all the folders present between public/ and my_photo.jpg were created with permissions 700 instead of 755. The image therefore comes out with a 403 error.
I contacted my host but it doesn’t seem to come from them.
Does anyone have a solution to my problem?
Thanks very much !
Solution for creating permissions
>Solution :
we will give 755 permission to storage and bootstrap folder permission
sudo chmod -R 755 bootstrap/cache
sudo chmod -R 755 storage
After that run the Storage Link command
php artisan storage:link
Also, Change in Laravel filesystems.php in the config folder
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL') . '/storage',
'visibility' => 'public',
'permissions' => [
'file' => [
'public' => 0644,
'private' => 0600,
],
'dir' => [
'public' => 0755,
'private' => 0700,
],
],
],
For more about detail check https://laravel.com/docs/9.x/filesystem#local-files-and-visibility