When I save images to storage they show in the storage/app directory, but they don\'t show in public/storage. I also noticed that a sto
That is actually how it should be! Laravel has a command to symlink your public directory to the storage directory:
php artisan storage:link
The idea is to keep a persistent storage between deployments.
This convention will keep your publicly accessible files in one directory that can be easily shared across deployments when using zero down-time deployment systems like Envoyer.
https://laravel.com/docs/5.5/filesystem
For windows users, I have tested this with Windows 10 and Laravel 7
Steps:
<project_root>/public
directory and run rmdir storage
- it will remove the linkphp artisan storage:link
to link againThe links should now be refreshed and viewable without issues.
I had this problem and I fixed it by adding this to my deployment script:
cd public
rm storage
cd ..
php artisan storage:link
Before you do that, you can SSH into your deployment server and navigate to the /public
folder. You might see a storage
folder in there, and you should notice it's a symlink. You should leave it there and add my above commands to your deployment script.
If you remove storage link manually, you'll need to skip these on the first deployment:
cd public
rm storage
cd ..
Then every deployment after, you can do:
cd public
rm storage
cd ..
php artisan storage:link
If you don't do that, your deployment will fail probably because if rm storage
throws an error, it will fail the build. Pay close attention to what I'm saying. You must be very specific when doing CLI commands, unless you can add some bash script that handles the 2 cases where ./public/storage
exists (1) and when it doesn't (2).
You might gloss over my mention about deleting the storage
symlink reference manually, but don't forget that if you deployment script does it and then fails for another reason, the symlink will be gone
.
Someone should post an answer that uses a bash script to ensure both cases can be handled. I don't have the skill for that.
NOTE:
php artisan storage:link
only works while you are in the root directory of your project. That's why my above script starts withcd public
and why it doescd ..
. If you aren't in the root at the time, thephp artisan
command will fail.
You can always delete the link:
cd public
rm storage
And create a new one without using the storage:link
command if you need to link different locations:
\File::link(storage_path('dir1'), public_path('dir2'));
Or create a symlink manually:
ln -s /full/path/to/storage/dir1 /full/path/to/public/dir2