1

how to create symlink from public/storage to storage/app/public in homestead on window. and how do i access my files from browser, so if i visit that image url via browser then it will show that particular image.

actually i'm building an api which accessible from any domain , so i have to return the url of that particular image which is uploaded. so it will be shown of front end. i'm also saving path to database which is - storage/app/public/image.png . what should i do now..

I'm new to file system so may be i need steps by step instruction.

i will be so thankful for the help

Rahul
  • 929
  • 2
  • 8
  • 17

3 Answers3

1

I had the same problem creating a symbolic link from the "public" folder to a location on the "storage" directory.

I tried to use "mklink /j" as well to create the symlink. However, when I "vagrant ssh" to the virtualbox, I found that it did not actually create the link correctly. Attempting to "cd" to the created link would cause an error. Also it wasn't shown as a symlink in the usual linux notation.

To allow the symlink to be created in the virtualBox:

  • Open "Local Group Policy Editor".
  • Go to: Computer Configuration | Windows Settings | Security Settings | Local -Policies | User Rights Assignment
  • Find the "Create symbolic links" policy and add your logged in user to it.
  • Restart your host windows machine. ssh to your virtualbox. You may need to run "vagrant up" as an Administrator by opening your CMD using "Run as administrator" option.
  • Go to your "public" folder, and create your symbolic link using the linux "ln -s" command. It should work now.

I was using Windows 10, but the above should be the same for Windows 7. The "Create symbolic links" policy may be located somewhere slightly different for earlier versions of Windows.

Credit should go to this blog: Symlink support in Windows and Virtualbox

Glenster
  • 1,187
  • 2
  • 13
  • 31
  • well i'm using git shell to ssh to homestead.. well when i visiting to my laravel project public folder.. then what command i should type.. after ```ln -s``` , tried ```public/storage storage/app/public``` and it didn't worked ? – Rahul Jul 08 '16 at 17:15
  • Hi, when you say it didn't work. What error did you get? After doing the above steps in Policy Editor, ssh to homestead (vagrant ssh). Then cd to your app public folder. You will be able to create the symlink via a command like this: **ln -s ../storage/app/public storage** – Glenster Jul 11 '16 at 09:58
  • Before trying these steps, I'd encourage you to just restart Windows. For me, running as administrator was not enough, and I still got "Protocol error" when trying to create symlinks. Here was what worked: https://stackoverflow.com/a/60741351/470749 – Ryan Mar 18 '20 at 14:17
0

I tried this and it works. Running homestead on VirtualBox on Windows 10:

  1. Open cmd as administrator
    • Click Start->Run
    • Type 'cmd', and press ctrl-shift-enter
    • Select 'yes' from the pop-up window
  2. Type the following command:mklink /D c:\<project_directory>\public\storage "/home/vagrant/<project_directory>/storage/app"

Then the storage/app will be accessible from public/storage in Homestead VM. Note that this is assuming C:\ is shared as /home/vagrant in Homestead VM.

Benny
  • 11
  • 2
-1

On a MacOS you need to go to your Homestead folder and:

  1. run: vagrant ssh
  2. navigate to your project root folder
  3. run: php artisan storage:link

And you are done.

If you do this without ssh to vagrant then it will not work.

christostsang
  • 1,701
  • 3
  • 27
  • 46