skip to Main Content

I am hosting my laravel on a Cpanel that not sups symlink so when I run storage:link i get this error :

symlink() has been disabled for security reasons

when I contacted my provider they told me that they can’t open it but I have to make changes in my file system to read from the storage itself.
now my question is how can I change the config/filesystem.php to not read from symlink but the storage folder itself. thanks in advance

2

Answers


  1. You have a couple options.

    If you have access to the command line, you can attempt to manually create the symlink yourself. It’s possible they disabled the PHP symlink() command, but the OS ln command may still be available to you. From the command line:

    ln -s /path-to-project/storage/app/public /path-to-project/public/storage
    

    If you don’t have access to the command line, you can attempt to run the command from PHP using one of the program execution methods (exec(), shell_exec(), etc.). However, if they’ve disabled symlink(), they’ve probably disabled all of those, as well. To attempt this, create a temporary route, hit it once, then delete it:

    Route::get('temp-create-link', function () {
        exec("ln -s ".escapeshellarg(storage_path('app/public')).' '.escapeshellarg(public_path('storage')));
    });
    

    If you don’t have a way to run the ln command, or if it has been disabled at the OS level, then you’ll need to manually create your public/storage folder and update your filesystem config to point to it. Once you’ve created the public/storage folder, open your config/filesystems.php file and update the root key for your public disk to point to it:

    'disks' => [
    
        // ...
    
        'public' => [
            'driver' => 'local',
            // old value: 'root' => storage_path('app/public'),
            'root' => public_path('storage'),
            'url' => env('APP_URL').'/storage',
            'visibility' => 'public',
        ],
    
        // ...
    
    ],
    
    Login or Signup to reply.
  2. I too had got this problem when I had used shared hosting. Actually storage:link implementation is not a tough, but you do not have permission to use that command.

    1. Create a folder inside public folder. In my case I have created uploads, you can make any folder and sub folders.

    2. In Controller, upload file with public_path(). For example purpose I am uploading image.

        // In html form, file name is cover_image
        if($request->file('cover_image')){
             $image = $request->file('cover_image');
             $extension=$image->getClientOriginalExtension();
             $file_name = 'File-'.date('Y-m-d-h-i-s').'.'.$extension;
             $destination_path = public_path('/uploads/');
             $result=$image->move($destination_path,$file_name);
             if($result){
                $data['cover_image']=$file_name;
             }
          }
      
    3. Use asset() to access files. For example purpose I am using img tag.

      <img src="{{ asset('uploads/'.$item->cover_image) }}">
      
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search