I’ve created a storage link with php artisan storage:link
and it’s working totally fine on localhost, However, when I deploy my project on a shared hosting, it does not render any images. This is my hosting directory structure:
- home2/username
: + other hosting folders
: - MyLaravelWebSite
: : + other_laravel_folders
: : - storage
: : : - app
: : : : - public
: : : : : -images
: : : : : : * some-image.jpg
: : : : * gitignore
: : : + framework
: : : + logs
: - public_html
: : + assets
: : + storage // symlink
: : * index.php
Images are uploading without any issue, but when I try to render them they do not render, while they’re being rendered absolutely fine on localhost. I think the symbolic link is not working. How can I make it work?
P.s: I don’t have any access of CLI on cPanel.
4
Answers
Update filesystems.php
put this in
filesystems.php
then your all file will be saved inpublic/uploads
folderand to get url this function
Storage::disk('public')->url($dbImageUrl);
will be workthis is for cpanel if you are not able to create symlink then
You can use PHP and Laravel helper methods to do the same, just run this code once (e.g. add it in your controller and call it once) to create storage link manually:
Try creating a file in your public folder (
filename.php
). Add the code and savebrowse the file you created
site.com/filename.php
Credit: https://www.nicateliyev.com/en/post/how-create-symbolic-link-laravel-website-cpanel
An alternative to the answers above with out making any changes to the file config system is to
Delete the storage link folder created on your local host from your c-panel
Create a route to run you php artisan storage:link command as below
Router::get('/storage_link', function (){ Artisan::call('storage:link'); });
on your bowser got to the route /storage_link,.. this will create a new system link to you storage file