John Davidson

php - Laravel 9 Storage images error 403 Forbidden

0 comments
Message:


Good day.
I've been dealing with a problem for a couple of days that hadn't happened to me in any other Laravel project.
I use Angular and Ionic(angular) to connect to a VPS where my Laravel 9 project is hosted. I've already run the php artisan storage:link command and given permission 775 to the storage folder.


In this same VPS I have more Laravel projects where I upload images with Storage in the same way as in this project


request()->file('file')->store('public/'.$id);


This successfully saves the image and I can see it in my storage folder.


Now when I want to see from a browser or from the app that route where the image is, it gives me the error 403 Forbbiden You do not have permission to access this document.
The route I use is with this structure:


https://exampledomain.com/storage/1/exampleimg.png


But if I give it permission 775 again, it already shows the image without any problem, but the new images that are uploaded will not be shown and will continue saying 403 Forbbiden You do not have permission to access this document.


I cannot be giving permission 775 every time a new image is uploaded since it is a project that will be handled by dozens of people.


The strangest thing is that only in laravel 9 I have this problem because in my past projects laravel 7, 6, 5.8 all projects upload images and I only had to give permission to the storage folder once.



My Answer:
One possible solution to this issue is to check the ownership and group of the storage folder. Make sure that the ownership and group are set correctly so that the web server (such as Apache or Nginx) has permission to access the files.

You can try running the following command to set the ownership and group of the storage folder:


sudo chown -R www-data:www-data storage


Replace `www-data:www-data` with the appropriate user and group that your web server is running as.

Additionally, you can try setting the permissions recursively on the storage folder to ensure that all files and folders have the correct permissions:


sudo chmod -R 775 storage


After running these commands, try uploading a new image and accessing it through the browser to see if the issue is resolved. If the problem persists, you may need to check the configuration of your web server to ensure that it has the necessary permissions to access the files in the storage folder.

Rate this post

3 of 5 based on 3060 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us