Creating symlink in Laravel (windows)
Asked Answered
S

4

7

I'm currently having some problems with creating symlink in my Laravel project. I'm currently on Windows 10 OS and I'm using GitBash.

I need to create symlink from storage/app/products_content to public/products_content

For that, I'm using the following command:

ln -s storage/app/products_content public/products_content

The problem is, I'm getting the following error:

ln: failed to create symbolic link 'public/products_content': No such file or directory

But, when I try to create a symlink like this:

ln -s storage/app/products_content products_content

It creates it with no errors, but the folder is in my root directory, not in /public.

What causes this error, could it be permission issues? I'm running GitBash as administrator. Any help appreciated. If I need to provide any additional code, let me know.

Syllepsis answered 30/7, 2019 at 11:17 Comment(6)
Does public even exist?Fiasco
It does. My project would't work otherwise. Also, when I create products_content manually in public dir and run this command, it says that folder already exists.Syllepsis
Well, pls check your paths in your question vs windows, since they differ from what your are asking.Fiasco
What do you mean they differ?Syllepsis
you say: storage/app/products_content => public/products_content, then: storage/app/public => public/products_contentFiasco
You're right. I edited my question. Still having the same problem.Syllepsis
F
11

Try going into the public folder, then do:

ln -s ../storage/app/products_content products_content

And if that doesn't work, open Command Prompt (not PowerShell) And "browse" to the public folder, then do:

mklink /D products_content ..\storage\app\products_content

mklink is the same as ln except that the target and link is switched.

Fiasco answered 30/7, 2019 at 11:46 Comment(4)
then maybe you need to re:install git-scm with a newer version, that has better support for symblinks, you also need to tick in that symblinking should be activated during the installation process.Fiasco
this needs to be in the docs for windows users!Undershorts
Thank you! This is what I needed. It's a couple years later and in case someone sees this, yes, it is still true. Running Windows, serving locally with Laragon. I tried a dozen different things and this was the fix.Yanez
You need to run the command prompt as administratorKalikalian
E
6

Just run: php artisan storage:link and modify your path to: storage/products_content

Evulsion answered 30/7, 2019 at 11:41 Comment(3)
Problem with this is, the project is already in production, there's a lot of images already there. If I do this, my previous images wont work anymore.Syllepsis
@zlatangoralija gotcha.Evulsion
This does not work on Windows and this was Windows specific question.Extortionate
C
6

You may configure additional symbolic links in your filesystems configuration file. Each of the configured links will be created when you run the storage:link command:

'links' => [
    public_path('storage') => storage_path('app/public'),
    public_path('images') => storage_path('app/images'),
],
Chifley answered 5/11, 2020 at 6:24 Comment(1)
Right from the docs. laravel.com/docs/8.x/filesystem .Hutchison
F
1

The problem is when using windows

solution:

In my case, I am using laragon.

LINK CREATION (This is because the php artisan storage: link does not work on windows)

  • For this case, you will have access to images
  • Open cmd as administrator
  • Verify that public access does not work (public \ images)
  • Then copy in cmd: mklink / J C: \ laragon \ www \ project-name \ public \ images C: \ laragon \ www \ project-name \ storage \ app \ images

This would be similar to: php artisan storage: link

Take into account that to save in images it must be configured in the filesytem file (conf / filesytem)

   'links' => [
    public_path('storage') => storage_path('app/public'),
    public_path('images') => storage_path('app/images'),
], 

credits : more info

Frasco answered 16/10, 2021 at 18:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.