Try using the asset helper. Also have a look at https://laracasts.com/discuss/channels/laravel/images-dont-load-get-image-404-not-found
403 access forbidden on storage/public folder
Hi, I have seen the posts from a few other people having the same issue, but although I have tried the suggested solutions I still have this problem getting a 403 access forbidden when trying to access the image url on the browser. I am not sure if it is because my Laravel app is running on Docker, maybe some further input would help.
What I have done far:
- I have created a symlink of storage directory to public (I have tried using both absolute and relative path):
ls -lah public
total 48
-rw-r--r--@ 1 lykos staff 6.0K Feb 9 19:24 .DS_Store
-rw-r--r--@ 1 lykos staff 670B Feb 14 21:00 .htaccess
drwxr-xr-x@ 3 lykos staff 96B May 31 2022 css/
-rw-r--r--@ 1 lykos staff 0B May 30 2022 favicon.ico
-rw-r--r--@ 1 lykos staff 1.7K May 30 2022 index.php
drwxr-xr-x@ 3 lykos staff 96B May 31 2022 js/
-rw-r--r--@ 1 lykos staff 71B Jun 7 2022 mix-manifest.json
-rw-r--r--@ 1 lykos staff 24B May 30 2022 robots.txt
lrwxr-xr-x@ 1 lykos staff 21B Feb 13 16:21 storage@ -> ../storage/app/public
- In the container that runs php the files & folders are owned by www-data. I can cd into the public/storage folder and if I run the ls command I can see the contents, so folders and files like 1/my-test-image.jpg etc
// from within the running php container
/var/www/html # ls -lah public/
total 24K
drwxr-xr-x 11 www-data www-data 352 Feb 14 13:39 .
drwxr-xr-x 37 root root 1.2K Feb 14 13:39 ..
-rw-r--r-- 1 www-data www-data 6.0K Feb 9 19:24 .DS_Store
-rw-r--r-- 1 www-data www-data 668 Feb 14 17:30 .htaccess
drwxr-xr-x 3 www-data www-data 96 May 31 2022 css
-rw-r--r-- 1 www-data www-data 0 May 30 2022 favicon.ico
-rw-r--r-- 1 www-data www-data 1.7K May 30 2022 index.php
drwxr-xr-x 3 www-data www-data 96 May 31 2022 js
-rw-r--r-- 1 www-data www-data 71 Jun 7 2022 mix-manifest.json
-rw-r--r-- 1 www-data www-data 24 May 30 2022 robots.txt
lrwxr-xr-x 1 www-data www-data 21 Feb 13 16:21 storage -> ../storage/app/public
/var/www/html #
- I haven't done any changes in the config file, it is with the default settings so far, but I'm posting it anyway for ref
<?php
return [
'default' => env('FILESYSTEM_DISK', 'local'),
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
'throw' => false,
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
'throw' => false,
],
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
'url' => env('AWS_URL'),
'endpoint' => env('AWS_ENDPOINT'),
'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false),
'throw' => false,
],
],
'links' => [
public_path('storage') => storage_path('app/public'),
],
];
- This is my code
// Livewire method
public function mount()
{
$this->mainImageUrl = $this->post->getFirstMediaUrl();
}
// Livewire view component
<div class="space-y-4">
<img src="{{ $mainImageUrl }}" alt="" />
</div>
The mainImageUrl is http://localhost:8888/storage/1/my-test-image.jpg, so either when I try to access this url from a new tab in the browser or in the network tab in Developer Tools, I get the 403 status.
Any ideas what am I doing wrong? As I mentioned and in the begining this app is running on Docker (not Sail)
Please or to participate in this conversation.