Support the ongoing development of Laravel.io →
posted 7 months ago
Laravel

Images stored in the public/storage directory are not displaying on the live server (shared hosting environment), but they work perfectly on localhost.

Relevant Code

Trainee.php Method

public function getProfilePicture()
{
  if ($this->picture && Storage::disk('public')->exists($this->picture) == 1) {
         return Storage::disk('public')->url($this->picture);
    }

    return asset('/images/blank_profile_picture.png');
}

Blade Template

<img src="{{ $trainee->getProfilePicture() }}">

filesystems.php Configuration

'disks' => [
        'local' => [
            'driver' => 'local',
            'root' => storage_path('app/private'),
            'serve' => true,
            'throw' => false,
        ],

        'public' => [
            'driver' => 'local',
            'root' => storage_path('app/public'),
            'url' => env('APP_URL').'/storage',
            'visibility' => 'public',
            'throw' => false,
        ],
],

Commands Executed on Shared Hosting (via SSH)

Below are the commands I ran to set up the symbolic link for the storage directory:

php artisan storage:link
  INFO  The [public/storage] link has been connected to [storage/app/public].
chmod -R 755 storage
chmod -R 755 public/storage

Verifications

After running the commands:

  1. The symbolic link was created successfully:
ls -l public
lrwxrwxrwx 1 user user 61 Dec 17 10:22 storage -> /home/customer/www/.../storage/app/public

... contains the app path that I'm passing in .env as APP_URL

  1. The file exists in the storage/app/public/trainee-profile-pictures directory:
ls -l storage/app/public/trainee-profile-pictures/
-rwxrwxr-x 1 user user 26990 Dec 17 07:36 gAgoBddnYT7SH0eiV2u000bqZT5j2TGQjcoedHlj.jpg```

Expected Output

The getProfilePicture() method in the Trainee.php model should return the correct URL of the image, and the <img> tag in the Blade template should display the image.

Debugging Observations

Actual image path:

  • /storage/app/public/trainee-profile-pictures/gAgoBddnYT7SH0eiV2u000bqZT5j2TGQjcoedHlj.jpg

Values observed during debugging:

$this->picture = trainee-profile-pictures/gAgoBddnYT7SH0eiV2u000bqZT5j2TGQjcoedHlj.jpg
Storage::disk('public')->exists($this->picture) = 1
$trainee->getProfilePicture() = https://.../storage/trainee-profile-pictures/gAgoBddnYT7SH0eiV2u000bqZT5j2TGQjcoedHlj.jpg
storage_path('app/public/'.$this->picture) =
/home/customer/www/.../storage/app/public/trainee-profile-pictures/gAgoBddnYT7SH0eiV2u000bqZT5j2TGQjcoedHlj.jpg

Observations:

  • The symbolic link appears to be created correctly.
  • The image exists in the specified directory.
  • Despite this, the fallback image is being returned by the getProfilePicture() method.

Request

Please guide me on:

  1. Whether there’s an issue with the symbolic link or file permissions.
  2. Any misconfiguration in the filesystems.php or hosting environment.
  3. Steps to ensure the images display properly on the live server.
Last updated by @faizankamal7 7 months ago.
0

Can you find the images yourself 'through' the symlink. E.g. does ls public/storage/ list the content of storage/app/public? Then try ls public/storage/trainee-profile-pictures etc. If not, then the sy

Something to try is make your own symlink instead of relying on artisan: sudo ln -snf /home/customer/www/<path>/storage/app/public /home/customer/www/<path>/public/storage

If that all works, then I'd guess it's a problem with reading the files. Seems like you already checked permissions, so maybe try dumping the images into the actual public folder directly, instead of using the symlink (just delete it), and see if the code finds the files then.

Is there any error message logged when failing to read the images?

Thanks for making your question so easy to read

Last updated by @ianflanagan1 7 months ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.