Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

laravel - storage:link not working on hosting cPanel

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:

use IlluminateSupportFacadesFile;

File::link(
    storage_path('app/public'), public_path('storage')
);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...