laravel / framework

The Laravel Framework.
https://laravel.com
MIT License
32.32k stars 10.95k forks source link

Linking The Storage Directory Command #15439

Closed edward-aslin closed 8 years ago

edward-aslin commented 8 years ago

The command which links the storage directory...

php artisan storage:link

This appears to create an absolute link. It means that the symlink does not work properly when using homestead.

To get around this i create a symlink with a relative path

ln -s ../storage/app/public public/storage

Should this not be the default behaviour?

Steps To Reproduce:

Use the command when using homestead for the local environment. php artisan storage:link

themsaid commented 8 years ago

@edd-smith why wouldn't it work by default? What errors do you receive?

edward-aslin commented 8 years ago

For me, using the "storage:link" command, the symlink created does not work inside the homestead VB and as such you can not upload or access files in the storage folder.

However manually creating a relative symlink fixes this problem.

themsaid commented 8 years ago

By doesn't work you mean erroring or just doesn't take effect?

edward-aslin commented 8 years ago

It silently fails. No error message, it doesnt take effect.

henriquebremenkanp commented 8 years ago

I just submitted a PR to make use of relative paths. #15584

henriquebremenkanp commented 8 years ago

@edd-smith you have to do vagrant ssh and run storage:link from inside the vm for it to work right now.

It seems like you're running storage:link from your host OS and it will link to /Users/you/laravel/storage/app/public, which doesn't exist inside the vm. If you create from inside the vm it will be /home/vagrant/laravel/storage/app/public, and you won't be able to use the symlinks in finder, but it will work on the browser.

edward-aslin commented 8 years ago

Sounds about right @henriquebremenkanp

themsaid commented 8 years ago

@edd-smith

Use the command when using homestead for the local environment.

The whole time I thought you're using the command from inside the vm :)

edward-aslin commented 8 years ago

Apologies for the confusion and thanks for helping solve @themsaid

I see the pull request was denied. Therefore, would you deem it worthwhile to adding a quick note to the documentation regarding this? Or is it silly obvious to most Homestead users?

Litaya commented 7 years ago

I find the main reason(for me) is that only absolute path will work well.

So: For my local mac environment with homestead, using vagrant ssh login into virtual system, then run php artisan storage:link works well

For my server CentOS6.8 environment without homestead, using ln -s absolute_path absolute_path command works well, too. ( but php artisan storage:link doesn't work, don't know why).

brickgale commented 7 years ago

I am using larvel 5.2 and running windows 10 with xampp. Tried running ln -s ../storage/app/public public/storage on gitbash but unfortunately it fails. Gives me ln: failed to create symbolic link 'public/storage/public': File exists. Is there anyway to solve this?

JohanIskandar commented 7 years ago

My configuration as follows Laravel Version: 5.4.12 Voyager Version: dev-release/v0.11" PHP Version: 7.1.0

When php artisan storage:link, it gives me errors The "public/storage" directory already exists.

Please help,

thanks, Johan

jingaworks commented 7 years ago

@JohanIskandar Delete the storage directory from public/ directory and do the command again. I had the same problem and this is how I did it.

Quadriphobs1 commented 7 years ago

I am running laravel 5.5 and i just uptated my homestead to 3.1.0 and my virtual box to 5.2, everythings works fine before the update but after ii update the files under the storage before update works fine but the new files i just upload there doesnt synchronize, i mean i cant read or access them, if i ssh into the public\storage\folder\ and do ls -l all the old files will be loaded but if ssh into storage\app\public\folder\ and do ls -l all the old and new files will be loaded alongside as well, i have done vagrant provision, please what am i missing, i am on windows 10 64 bit

liucf commented 7 years ago

laravel 5.5 + homestead to 3.1.0 got same issue.

liucf commented 7 years ago

@themsaid laravel 5.5 + homestead to 3.1.0 got same issue.

edward-aslin commented 7 years ago

@liucf did you SSH into homestead and run the command from inside the VM?

Quadriphobs1 commented 7 years ago

Thanks for your reply @edd-smith , i ran the command in ssh, its saying symlink() protocol error, if i run the command in the project root directory it will runs and link the storage folder, but i can access it via the Homestead, It if start the server in my root project, i mean if i php artisan serve and try to access the files in the storage directory, it will see the file and loads correctly, but if i open my project via the homestead address and try to access the file in the storage, i keep getting 404 error which means not found. Also if i ssh into my project directory and move into the public folder the storage folder will be listed but its in red color and if i try t access it i keep getting protocol error.

daniel-farina commented 6 years ago

If you are on windows you can run this command from Gitbash as an Administrator. That's the trick .

image

ln -sr storage/app/public public/storage
AdrianKuriata commented 5 years ago

If you are using windows and homestead, if you have set:

      type: "nfs"
      mount_opts: ['nolock,vers=3,udp,noatime,actimeo=1']

in the Homestead.yaml and storage:link not works for you, just remove these options from the Homestead file configuration and everything will be okay.

easterneas commented 4 years ago

If you are on windows you can run this command from Gitbash as an Administrator. That's the trick .

image

ln -sr storage/app/public public/storage

I tried using your command through Gitbash as an Administrator, but it only updated once, and once I tried to upload again, the items in public folder won't update. Hence, 404.

Luckily, there is built-in Windows command that can link to a specific path, like mklink:

mklink /D "Link Folder" "A:\bsolute\Path\To\Target\Folder"

Make sure that the Target option should be an absolute path. Otherwise, it will throw an error.

mklink /D ".\public\storage\" "P:\ath\to\your\project\storage\app\public\"

And, yes, I tested by doing copy-paste on it, and it worked beautifully. Hope this helps :)

P.S.: I think this should be incorporated within php artisan storage:link in the future.

rodrigodesouza commented 4 years ago

If you are on windows you can run this command from Gitbash as an Administrator. That's the trick .

image

ln -sr storage/app/public public/storage

não estava conseguindo até usar este comando com o "r" adicional. ln -s storage/app/public public/storage -> ln -sr storage/app/public public/storage

izshreyansh commented 4 years ago

If this doesn't work inside windows even with Run CMD As Administrator mode.

alexlovar commented 4 years ago

For me, using the "storage:link" command, the symlink created does not work inside the homestead VB and as such you can not upload or access files in the storage folder.

However manually creating a relative symlink fixes this problem.

hi, could you please, tell where is the path on ubuntu 18, to manually edit this simlink?

izshreyansh commented 4 years ago

@alexlovar /public/storage

sandeepstha46 commented 1 year ago

@jingaworks Thank you mate.