I am using the default laravel folder structure and the filesystem public
:
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL') . '/storage',
'visibility' => 'public',
],
Everything runs on docker and the complete laravel folder is mounted into /var/www/html
:
#... Laravel PHP-FPM service definition
volumes:
- "./:/var/www/html"
#...
When I run php artisan storage:link
and then cd /var/www/html/public
and ls -la
I see that the symlink exists:
lrwxr-xr-x 1 root root 32 May 5 11:19 storage -> /var/www/html/storage/app/public
If i then check to see if the linked folder also exists in the container cd /var/www/html/storage/app/public
everything is there as expected.
Also, when checking ls -la /var/www/html/public/storage/
directly it shows me the content of the linked folder. So everything is working from symlink perspective
# ls -la /var/www/html/public/storage/
total 512
drwxr-xr-x 4 www-data www-data 128 May 5 11:21 .
drwxr-xr-x 11 www-data www-data 352 Apr 19 14:03 ..
-rw-r--r-- 1 www-data www-data 14 Feb 16 16:58 .gitignore
-rw-r--r-- 1 www-data www-data 519648 May 5 10:58 sample.png
However, when opening the url /storage/sample.png
the server returns 404.
The remaining contents of /var/www/html/public
do work fine, so for example /var/www/html/public/test.png
is visible under localhost/test.png
.
On production, everything works fine though. Any ideas why the symbolic link is not working on the local system while the link is actually correct?
I already tried removing the storage link and setting the symlink again.
You mentioned that you are using docker. I think the reason that it doesn't work locally, but in production, could be that there is a configuration shift between the two deployments.
For it to work the Nginx container must have access to the storage folder, since it is supposed to serve assets that are located there. I'm guessing that is currently not the case and only the public folder is mounted.
Check if the entire project or both ./public
and ./storage
are mounted into the Nginx container.
Something like this:
services:
#...
nginx:
#...
volumes:
- "./public:/var/www/html/public:ro"
- "./storage/app:/var/www/html/storage/app:ro"
#...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With