Home » Php » php – Storage in laravel says symlink – no such file

php – Storage in laravel says symlink – no such file

Posted by: admin April 23, 2020 Leave a comment

Questions:

I deployed laravel app on shared hosting in public_html/app folder. Here is everything from public folder. In /../../files I have rest of files. When I do php artisan storage:link in files folder my console says

[ErrorException]                      
  symlink(): No such file or directory

On localhost I upload files to storage/uploads folder. What to do now? I tried to change links but nothing works for me…

How to&Answers:
  1. Go to /public directory and run:

    rm storage

  2. Go to Laravel root directory and run:

    php artisan storage:link


Edited on May 1st 2018

This problem comes when laravel project is moved/copied to some other folder.

The storage link is still there thus causing the exception error. public/storage folder exists and points to wrong location and it needs to be deleted with rm storage command.

After that run php artisan storage:link in terminal and it will create the storage link.

This needs to be done EVERY time when laravel is moved/copied/deployed!

Answer:

I’m face same error when use share hosting and my public directory move to public_html or different directory
like :
project directory in root name “project”
and public directory in root name “public_html”

when run artisan command by Artisan::call(‘storage:link’); then face this error.

Solution:
1st need to bind your public directory in app/Providers/AppServiceProvider register method

 $this->app->bind('path.public', function() {
    return base_path('../public_html');
 });

Now run the command its working fine

Answer:

This usually happens after moving Laravel app to another directory

The actual storage directory is “/AppName/storage/app/public/”

Laravel creates a symbolic link pointing to actual storage dir “/AppName/public/storage”

Other meaning

“/AppName/public/storage” points to => “/AppName/storage/app/public/”

On changing root app directory to “/AnotherAppName/” symlink will still point to the old path

“/AnotherAppName/public/storage” => “/AppName/storage/app/public/”

my solution is to manually update the symlink using

ln -sfn /AnotherAppName/storage/app/public/ /AnotherAppName/public/storage

Answer:

Delete the existing storage symbolic link (public/storage) and then run
php artisan storage:link command again.

Answer:

create new php file and put this code on the file:

<?php>
symlink('/home/CpanelUser/storage/app/public', '/home/CpanelUserpublic_html/storage');
?>

“CpanelUser” change to youre cpanel user name or host name.

upload this file to public_html folder (www) of site
execute file with write site name+this file in browser
done!

example:
my file name is symlink.php and site name is www.anysite.com
upload symlink.php to public_html folder in host and get web address in browser

http://www.anysite.com/symlink.php

after execute this file storage folder creite in public folder in laravel and link to storage folder in app.

Answer:

I was using Vagrant and had the same problem. I removed to storage directory in public/storage but couldn’t resolve the problem when using the command php artisan storage:link.

Therefore I connected with ssh to my vagrant box and ran the command there. It worked, so if you are running Vagrant and have the same problem this might help.

Answer:

Make sure the APP_URL configuration in .env file is set correctly. after that run following command line:

php artisan config:cache
php artisan storage:link