skip to Main Content

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


  1. Update filesystems.php

    'public' => [
                'driver' => 'local',
                'root' => public_path() . '/uploads',// upload file in public dir
                'url' => env('APP_URL').'/uploads', // help to get Storage::url() 
                'visibility' => 'public',
            ],
    

    put this in filesystems.php then your all file will be saved in public/uploads folder
    and to get url this function Storage::disk('public')->url($dbImageUrl); will be work

    this is for cpanel if you are not able to create symlink then

    Login or Signup to reply.
  2. 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')
    );
    
    Login or Signup to reply.
  3. Try creating a file in your public folder (filename.php). Add the code and save

    $targetFolder = $_SERVER['DOCUMENT_ROOT'].'/storage/app/public';
    $linkFolder = $_SERVER['DOCUMENT_ROOT'].'/public/storage';
    symlink($targetFolder,$linkFolder);
    echo 'Symlink process successfully completed';
    

    browse the file you created site.com/filename.php

    Credit: https://www.nicateliyev.com/en/post/how-create-symbolic-link-laravel-website-cpanel

    Login or Signup to reply.
  4. An alternative to the answers above with out making any changes to the file config system is to

    1. Delete the storage link folder created on your local host from your c-panel

    2. Create a route to run you php artisan storage:link command as below

      Router::get('/storage_link', function (){ Artisan::call('storage:link'); });

    3. on your bowser got to the route /storage_link,.. this will create a new system link to you storage file

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search