ln: failed to create symbolic link: Protocol error (in Vagrant)
Asked Answered
B

5

3

I'm using Laravel Homestead (Vagrant, Ubuntu). My host computer is Windows 10 running VirtualBox.

As admin (since I've already seen tons of answers that say lack of permissions is usually why people have problems with symlinks), I open Git Bash and run this:

vagrant@vboxHomestead:~/Code/myproject$ ls -lah /home/vagrant/foo/blah
total 0
drwxrwxrwx 1 vagrant vagrant 0 Mar 17 23:09 .
drwxrwxrwx 1 vagrant vagrant 0 Mar 17 22:36 ..
-rwxrwxrwx 1 vagrant vagrant 0 Mar 17 23:09 asdf.txt
vagrant@vboxHomestead:~/Code/myproject$ sudo ln -s /home/vagrant/foo/blah /home/vagrant/Code/myproject/storage/app/public/blah
ln: failed to create symbolic link '/home/vagrant/Code/myproject/storage/app/public/blah': Protocol error

What is the problem? Does it have something to do with the folder mappings of Homestead? How can I achieve my goal?

(My /home/vagrant/Code/ and /home/vagrant/foo/ map to separate drives on my Windows machine.)

P.S. And before trying the steps above, I even deleted the Homestead standard public symlink just to avoid other possible complications.

P.P.S. I've also tried adding this near the bottom (above the final end) of my Homestead Vagrantfile before spinning up the box:

config.vm.provider "virtualbox" do |v|
    v.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-root", "1"]
end
Buchholz answered 18/3, 2020 at 0:20 Comment(0)
B
2

I noticed that php artisan storage:link was now causing a "Protocol error" too.

So to narrow down the problem I created a totally fresh Homestead project and box and tried creating symlinks (including php artisan storage:link) in there but got the "Protocol error" too.

And I was very careful to be using Git Bash (my terminal / command line client) as Administrator, so I was already following the advice of most answers on StackExchange.

I also decided to move one of my Windows folders (the one that I'd had Homestead map to /home/vagrant/foo/) to be within the Windows folder that Homestead mapped to /home/vagrant/Code/.*

I decided to restart Windows 10 completely. Now after spinning up new vagrant boxes, php artisan storage:link and creating my other symlink worked.

*I'm not sure moving the Windows folder was even necessary. Maybe I could have left the folders on separate Windows drives. But at the time, I wanted to minimize possible complications.

Buchholz answered 18/3, 2020 at 14:13 Comment(1)
OMG....you my man are a legend! I have been pulling my hair out for days, totally destroyed my VM trying to work out why all of a sudden I couldn't run this command. Run as Admin wasn't working like everyone suggested, and then I found your post and worked straight away. Thank you so much!Chalet
L
1

When using Homestead, making a symlink in your public directory in Windows will also create a symlink on vagrant. The other way round may (!) create this error and will leave a not working symlink in your Windows directory.

Luncheonette answered 11/4, 2020 at 13:37 Comment(2)
Yeah but the link does not work then from within vagrant sshLuminescence
Used GNU bash version 4.4.x to create the lym link.... it's getting recognised by my pages running on homestead.Henze
G
0

The error sometimes return after you shutdown the VM and restart or still persists. Basically you need to again tell VirtualBox to enable symlinks. Here's the complete solution

Obviously have this in your vagrant file, as suggested above

config.vm.provider "virtualbox" do |v|
    v.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/Folder_Name", "1"]
end

I recommended comment out any sync folder and let default ./(at host) synced at /vagrant(at guest). This will make sure your shared folder(Folder_Name) name is always vagrant as mentioned here https://www.vagrantup.com/docs/synced-folders/. Also, you won't face issues with ssh

If the symlink protocol error returns after restart or still persists run

VBoxManage setextradata "VM_Name" VBoxInternal2/SharedFoldersEnableSymlinksCreate/Folder_Name 1

vagrant halt
vagrant up

vagrant ssh

Usually, VBoxManagee is located at C:\Program Files\Oracle\VirtualBox\

Verify working of symlink by going to /vagrant and running

touch test.txt && ln -s test.txt test1.txt

PS: I have tried this on Windows Home which has limited accessibility to security settings

Grasmere answered 20/5, 2020 at 1:31 Comment(1)
Unfortunately none of this worked (Windows Home).Luminescence
S
0

Protocol error means that the language of communication between the folders is different. You musst have the same version of PHP. So you have to bring the PHP in the VM and on your Windows OS on the same version state.

Go like this:

  • update your PHP on you computer (i.e. download from php.org)
  • then open cmd as admin
  • cd homestead -> vagrant up -> cd code -> cd "your-APP"
  • sudo apt update -> sudo apt upgrade
  • ln -sr storage/app/public public/storage

and now there is no error and the folder puplic/storage has been created. Good luck...

Shu answered 29/11, 2022 at 21:48 Comment(1)
don't forget to fit your path in the environment variables with the new PHP path!Shu
K
0

For anyone that uses Windows and nothing works... Check if your filesystem is NTFS. I had an external disk configured exFAT on which I was building a Laravel project. While trying to create symlinks with php artisan storage:link I got errors like

ErrorException
  symlink(): Inappropriate ioctl for device

Even from cmd.exe you'll get the message "The device does not support symbolic links." when trying manually with

mklink /d public\storage storage\app\public

According to msdn.microsoft, Symbolic Links are NOT supported on FAT16/32 and exFAT. See also this post

Kirstiekirstin answered 14/10, 2023 at 12:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.