johnDoe220's avatar

storage:link not working in host

Hi, on localhost by running the command php artisan storage: link the files I upload are transferred to the public folder, and everything works fine, but on the host I have a problem when uploading the file that instead of the file in The public folder is saved in Storage-> app-> public-> uploads, what can I do to fix this problem? Thank you.

0 likes
19 replies
johnDoe220's avatar

because use vps server , so I do not have access to ssh for run this command

neilstee's avatar

@johndoe220 well that's unfortunate because you need to re-run that command for it to be able to symlink again.

johnDoe220's avatar

thank's, so you say delete old zip file on host and again run command "php artisan storage:link" and upload again?

neilstee's avatar

@johndoe220 no, you don't need to re-upload anything. You need to run php artisan storage:link on the server itself not on your local.

johnDoe220's avatar

Unfortunately, no way running this command in vps server, anyway thank you

rovshena's avatar
1.Delete storage folder symbolic link in root_of_project/public/. If exists.
2.Run php artisan storage:link command.
3.Upload your files to root_of_project/storage/app/public/
johnDoe220's avatar

also told my dear neilstee, because use vps server , so I do not have access to ssh for run this command on host

Snapey's avatar

If you don't have ssh access then its not following the common definition of a VPS - its just shared web hosting

If you cannot run any artisan commands then you need to change where you store the uploads and write them directly to the public folder.

You can edit the config/filesystems.php file to redefine the default storage folder.

johnDoe220's avatar

it's true, but this is not standard method! i will used this method because i think beautiful method

Snapey's avatar

Then seek better hosting. You will run into lots of issues without ssh access

1 like
adamboniecki@gmail.com's avatar

In Laravel documentation, a symbolic link (symlink or soft link) from public_html/storage to storage/app/public should be created to make files accessible from the web.

(THIS PROCEDURE WILL CREATE SYMBOLIC LINK WITHIN THE LARAVEL PROJECT DIRECTORY)

Here are the steps on how you can create symbolic link in your Linux web server using SSH client:

  1. Connect and login to your web server using SSH client (e.g. PUTTY).

  2. Link storage/app/public_html to public/storage using the syntax.

ln -s target_path link_path Example (in CPanel File Directory)

ln -s /home/cpanel_username/project_name/storage/app/public /home/cpanel_sername/project_name/public_html/storage

arthurcervania's avatar

I have created an answer for this problem and I hope it works for you guys. I am using hostinger and purchased the premium one with the ssh access. I accessed my ssh to the main folder public html and run a similar code to this:

ln -s /home/u789790412/domains/tomvpn.appapistec.xyz/storage/app/public /home/u789790412/domains/tomvpn.appapistec.xyz/public_html/public

Now, do exactly as I do. Go to public_html/public folder and there you will see a public-> link folder like that. Rename that into storage.

Then the links will now work. The renaming is the trick i used because when i am developing it on my local device, i am using asset('storage/...'), that why i have adjust it and renamed the folder to storage.

I am uploading files and the link works fine because I think, the link also adjust when I had run the location link.

I hope this will help you.

Snapey's avatar

@arthurcervania Better to not put your entire codebase in the public domain.

Better than better is to not encourage others to do the same as you.

hansraj615's avatar

ln -s $(pwd)/storage/app/public $(pwd)/public/storage

try above command in command is not working

Please or to participate in this conversation.