Monday, February 14, 2022

[FIXED] Laravel smlink not found

Issue

I upload my laravel website to shared hosting ". Every things work except i am not able to retrieve images stored in the storage/public folder. I ran

 "php artisan storage:link" 

but it says not found. I also tried

rm storage

but the getthe message rm: cannot remove. Is directory php artisan storage:link output from ssh command


Solution

Note, I'm not addressing the original answer because it doesn't sound like it can be done. This is an alternate solution.

Solution

In your config/filesystems.php file, you'll see the following code (or something similar).

    'disks' => [

        'local' => [
            'driver' => 'local',
            'root' => storage_path('app'),
        ],

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

        's3' => [
            'driver' => 's3',
            'key' => env('AWS_ACCESS_KEY_ID'),
            'secret' => env('AWS_SECRET_ACCESS_KEY'),
            'region' => env('AWS_DEFAULT_REGION'),
            'bucket' => env('AWS_BUCKET'),
            'url' => env('AWS_URL'),
            'endpoint' => env('AWS_ENDPOINT'),
        ],

    ],

To link your public disk to a public directory without using OS symlinks, change the disks['public']['path'] to the public path of your choosing. For example,

    'disks' => [
        /** -- skipped code **/
        'public' => [
            'driver' => 'local',
            'root' => __DIR__ . '../public/images/`,
            'url' => env('APP_URL').'/images',
            'visibility' => 'public',
        ],
        /** -- skipped code **/
    ],

Another Solution

You can totally use the S3 storage as well. That will connect you with an AWS bucket that you can use.

Personal Anecdote

Shared hosting can be tricky with Laravel. I would transition away as soon as I could. I use Laravel Forge to deploy servers and Digital Ocean or AWS for hosting.



Answered By - Jacob

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.