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

urwxgrwx's avatar

laravel 9 storage not working

I created my site on shared hosting with laravel 9.but my dynamic placed photos are not loading.i don't have terminal access.when i open photos in new tab i get 404 error

0 likes
31 replies
urwxgrwx's avatar

@Sinnbeck example: public_html>storage>app>public>icon>icon.png public_html>storage>app>public>gallery>gallery.png

Sinnbeck's avatar

@urwxgrwx ok for that to work you need to run storage link. If you don't have shell access you can try calling this from a route

Artisan::call('storage:link');
1 like
Sinnbeck's avatar

@urwxgrwx if it works you should see the folder public_html/public/storage show up

1 like
urwxgrwx's avatar

@Sinnbeck there is only storage shortcut in my public folder.so it may not be working?

urwxgrwx's avatar

@Sinnbeck I created and went to the link but 500 I got SERVER ERROR error example Route::get('/linkstorage', function () { Artisan::call('storage:link'); });

Sinnbeck's avatar

@urwxgrwx did you import artisan at the top of the file? I recommend testing it locally first

1 like
urwxgrwx's avatar

@Sinnbeck yes i tried it directly on cpanel. do i need to do it locally and reload the project?

Sinnbeck's avatar

Storage shortcut? So are the files inside of that folder?

1 like
Sinnbeck's avatar

@urwxgrwx directly on cpanel? You can run artisan commands from there? Or do you just mean on the server?

No you cannot make the symlink locally and upload it. If you did upload the /public/storage folder then you need to delete it on the server and recreate it with storage:link (on the server)

urwxgrwx's avatar

@Sinnbeck just mean server.I created the symlink you said on the server but not working.sorry for the confusion.I don't have terminal access on cpanel.is there any other solution? :(

Sinnbeck's avatar

@urwxgrwx how did you make the symlink? Is there a button for that on cpanel or? (I have never used cpanel)

urwxgrwx's avatar

@Sinnbeck I created symlink.php in public_html into

Route::get("/storage-link", function () {

$targetFolder = storage_path("app/public");

$linkFolder = $_SERVER['DOCUMENT_ROOT'] . '/storage';

symlink($targetFolder, $linkFolder);

});

I wrote and went to the link

urwxgrwx's avatar

@Sinnbeck A storage shortcut has been created in public, so I can see it locally, but the shortcut is not visible in cpanel.

Sinnbeck's avatar

@urwxgrwx hmm maybe someone here knows cpanel and how to see if it was created.

Can you show the output of

$linkFolder = $_SERVER['DOCUMENT_ROOT'] . '/storage';
dd($linkFolder);

Maybe try it like this

$linkFolder = public_path('storage');
urwxgrwx's avatar

@Sinnbeck

$linkFolder = $_SERVER['DOCUMENT_ROOT'] . '/storage';

dd($linkFolder);

output:

^ "/home/konyayal/public_html/storage"

$linkFolder = public_path('storage');

dd($linkFolder);

^ "/home/konyayal/public_html/public/storage"

urwxgrwx's avatar

@Sinnbeck now web.php into add

Route::get("/storage-link", function () {

$linkFolder = public_path('storage');

});

/storage-link

didn't give an error.it just gave blank white page. but nothing seems to have changed

Sinnbeck's avatar

@urwxgrwx did you forget the rest of the code?

Route::get("/storage-link", function () {

$targetFolder = storage_path("app/public");

$linkFolder = public_path('storage');

symlink($targetFolder, $linkFolder);

}); 
urwxgrwx's avatar

@Sinnbeck it doesn't work that way.500 server error.

Route::get("/storage-link", function () {

$linkFolder = public_path('storage');

symlink($linkFolder);

}); again 500 server error

Sinnbeck's avatar

@urwxgrwx check your server logs to see what error that was :) or /storage/logs/laravel.log

urwxgrwx's avatar

@Sinnbeck I think I'm making a mistake in writing symlink $linkfolder on phpstorm looks wrong. laravel.log [2022-09-29 08:57:24] local.ERROR: Call to undefined function symlink() {"userId":3,"exception":"[object] (Error(code: 0): Call to undefined function symlink() at /home/konyayal/public_html/routes/web.php:48) [stacktrace]

urwxgrwx's avatar

@Sinnbeck [2022-09-29 09:01:46] local.ERROR: Call to undefined function symlink() {"userId":3,"exception":"[object] (Error(code: 0): Call to undefined function symlink() at /home/konyayal/public_html/routes/web.php:52) [stacktrace]

symlink($targetFolder, $linkFolder); line 54

Sinnbeck's avatar

@urwxgrwx Sounds like your host have disabled the symlink command. Contact them and ask them to enable it :)

Sinnbeck's avatar

@urwxgrwx Yeah that could very well be. But try asking your provider. Maybe it is just disabled by default, and they can enable it for you

Please or to participate in this conversation.