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

Demers94's avatar

Symbolic link from storage to public not working

Hi,

I'm building an application where user can upload mods. I'm storing the images for the mods in the /storage folder. Here's what the path looks like for a mod image :

/storage/mods/{ mod_id}/images/{ filename.extension}

Since we can't directly access the files in /storage from views, I made a symbolic link from the storage/mods to public/mods, using this command while in my project folder :

ln -s storage/mods public/mods

I'm trying to access an image like this :

mods/3/images/123.png

But I get a 403 forbidden in the console, and the image does not show up.

What am I doing wrong? Is that the proper way to access files in the /storage folder from views?

0 likes
11 replies
ohffs's avatar

Does your webserver follow symlinks? In Apache you have to set Options +FollowSymLinks for the directories concerned. Just a guess! :-)

Demers94's avatar

Does your webserver follow symlinks? In Apache you have to set Options FollowSymLinks for the directories concerned. Just a guess! :-)

I'm using MAMP, not sure if it has that option on or off by default.

I tried adding Options FollowSymLinks to the .htaccess in the /public directory, but I'm still getting 403. I created another .htaccess in the root of the Laravel project, same thing, and another one in the /storage directory, but it still didn't work.

Do I need to change the Apache config directly?

@ohffs

ohffs's avatar

It should be +FollowSymLinks (sorry - did an edit to my original answer). The option has to be inside a block as far as I remember - so something like :

.... various options ...
<Directory /var/www/html/project/public>
 Options +FollowSymLinks
</Directory>

That's just off the top of my head though! You might want to look in your apache error_log file too - it might give you another pointer :-)

Demers94's avatar

I checked http.conf and it looks like symlinks are allowed :

<Directory />
    Options Indexes FollowSymLinks
    AllowOverride None
</Directory>

I also looked at the Apache logs and saw this :

Symbolic link not allowed or link target not accessible: /Users/charles/Documents/Web/Mods/public/mods, referer: http://localhost:8888/Mods/public/

@ohffs I tried Options +FollowSymLinks as well but still no luck. :(

When I try to place it in a block in the .htaccess I get a 500 error though, and this in the log :

    /Users/charles/Documents/Web/Mods/public/.htaccess: <Directory not allowed here
ohffs's avatar

Just to check - if you do an ls -l /Users/charles/Documents/Web/Mods/public/mods does it work ok?

Demers94's avatar

@ohffs It prints this in the terminal :

lrwxr-xr-x  1 charles  staff  12  5 Dec 11:27 /Users/charles/Documents/Web/Mods/public/mods -> storage/mods

But it still doesn't work.

Thanks a lot for helping though!

ohffs's avatar
ohffs
Best Answer
Level 50

Can you try rm'ing the current symlink and doing ln -s /Users/charles/Documents/Web/Mods/public/mods/ /Users/charles/Documents/Web/Mods/public/mods - just to check the symlink is right? I'm not on a Mac just now so not 100% sure, but the ls output doesn't look quite right :-)

Edit: I'm about to head off for dinner - if that doesn't fix it hopefully someone else will chip in :-)

Demers94's avatar

@ohffs Removing it and remaking it did the trick! Last time I didn't use the complete path, only the storage/mods and public/mods parts.

I had to use this command though :

ln -s /Users/charles/Documents/Web/Mods/storage/mods/ /Users/charles/Documents/Web/Mods/public/mods

(I suspect this is just a typo on your part)

Thanks for the help, it's really appreciated. :)

1 like
ohffs's avatar

No worries - glad it fixed things. You don't really need the full path - the problem was just that you need the trailing '/' on the first argument with to make things happy on BSD-ish systems - on Linux/GNU I think it works either way. So you should be able to do (from your Mods directory) ln -s storage/mods/ public/mods for instance :-) Anyway - glad it's workng! :-)

1 like
rui.melo's avatar

The problem for me was that I had my symlink created in my Mac local environment instead of inside vagrant. I entered my vm through vagrant ssh and then manually created my symlink with ln -s "/home/vagrant/Code/project01/storage/app/public" storage within my public directory or you can just run php artisan storage:link.

3 likes

Please or to participate in this conversation.