Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

nscharrenberg's avatar

Symlink(): no such file or directory because public folder is in a diffirent directory.

Hi,

I'm working on an application and wanted to implement image uploading to my application. Now when i want to create the symbolic link for my files, i get the following error:

ErrorException : symlink(): No such file or directory

Exception trace:
symlink("/home/user/private/application/storage/app/public", "/home/user/private/application/public/storage")

Now i know what the cause of this is, but i don't know how to fix and/or have a workaround for it.

I only have my public folder in my html_root directory, and have the rest of the application in a directory outside of my html_root. In this case /home/user/private/application.

when i use php artisan storage:link it tries to find the public folder in my 'private' directory, but can't find it because my public folder is in html_root.

I've browsed through stackoverflow and laracast already, but haven't found a similar issue yet.

Does anybody have a solution for this problem?

Kind Regards,

0 likes
15 replies
salmon's avatar

Try to run the command manually

i.e.

ln -s /path/to/laravel/storage/folder /path/to/laravel/public/folder
1 like
nscharrenberg's avatar
nscharrenberg
OP
Best Answer
Level 1

@salmon and @rivory_g performing the ln command for the storage did not solve my problem.

It did create the symlink for the storage folder but seemed to have broken the upload functionality of Laravel.

Instead i went back to Laravel's official directory structure and placed my contents from html_root back to my private directory inside the public folder. I then created a symlink of the public folder and renamed it to html_root.

This way i can use everything without having to tweak or use custom commands.

Solution: Create a symlink of the public folder to your /home/user and remove your html_root folder or rename it.

ln -s /home/user/private/application/public /home/user

Inside your /home/user folder you now have a symlink named public. Rename this folder to html_root and it should make the website function normally.

ahishamali's avatar

while you are in the root folder do the following:

you can remove the existing link

rm public/storage

then re-link it again with the php artisan storage command

php artisan storage:link
6 likes
JamesJohnathon's avatar

0

Problem solved by placing my html_root content back to my private folder in /home/user/private/application and creating a symlink of my public folder that goes to my /home/user and renaming the /home/user/public folder to /home/user/html_root (and keeping the symlink intact).

So i remain with the official Laravel directory structure and make a faux (symlink) of the public folder.

With this i can use the php artisan storage:link normally without creating a custom Command.

Regards: James Johnathon https://www.contactyahoousa.com

minaFaragAmin's avatar

thanks :) rm public/storage then run php artisan storage:link fixed the issue

chanaks's avatar

The following commands will help you remove the symbolic link from the public folder:

cd public

rm storage

After removing the symbolic link change directory to the main folder using: cd ..

Now create the symbolic link with the following command:

php artisan storage:link

After running the command successfully, you should get the following message

The [public/storage] directory has been linked.

debanjanroy's avatar

After 1 hour I have got a solution:

Write down the code on your web.php route file:

Route::get('/linkstorage', function () { $targetFolder = base_path().'/storage/app/public'; $linkFolder = $_SERVER['DOCUMENT_ROOT'].'/storage'; symlink($targetFolder, $linkFolder); });

After than navigate to your url/linkstorage

it's helped me.

8 likes
sergitet94's avatar

Route::get('/linkstorage', function () { $targetFolder = base_path().'/storage/app/public'; $linkFolder = $_SERVER['DOCUMENT_ROOT'].'/storage'; symlink($targetFolder, $linkFolder); }); this did the magic for folks on shared hosting.

Please or to participate in this conversation.