Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating symlink in Laravel (windows)

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.

like image 645
zlatan Avatar asked Jul 30 '19 11:07

zlatan


4 Answers

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.

like image 107
Anuga Avatar answered Nov 06 '22 15:11

Anuga


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'),
],
like image 23
Yanislav Tankov Avatar answered Nov 06 '22 15:11

Yanislav Tankov


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

like image 6
JCode Avatar answered Nov 06 '22 16:11

JCode


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

like image 1
WILFREDO FERMIN Avatar answered Nov 06 '22 16:11

WILFREDO FERMIN