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

janmoes's avatar

Laravel symlink not working correctly

Hi there, I've recently made a new laravel project, where I can upload images for specific models. I created a symlink using php artisan storage:link and images are loaded in correctly by doing <img class="image rounded-circle" src="{{asset('storage/img/profile_img/'.$user->image)}}" /> for example. I uploaded my project on a shared hosting. But for some reason uploaded images wont go to the symlink. Some static images are working. (which are already in the folder). But whenever I try to upload an image, it is being stored in the original /storage, but not in the public_html/storage. I already tried running the storage artisan command via a route and some other common ways to fix it. But without any luck.

0 likes
9 replies
Sinnbeck's avatar

Does the directory /public/storage exist?

janmoes's avatar

@Sinnbeck Locally yes, and images are being uploaded in there correctly. On that shared hosting it is within public_html

janmoes's avatar

I managed to fix the issue. I'm not sure why. But for some reason the generated storage link locally didn't work on my shared hosting. By copying all files from public to /public_html I guess somehow /storage became an actual folder instead of a symlink one, I removed the folder and ran this script

<?php
$targetFolder = $_SERVER['DOCUMENT_ROOT'].'/../cnnect/storage/app/public';
$linkFolder = $_SERVER['DOCUMENT_ROOT'].'/storage';
symlink($targetFolder,$linkFolder);
?>

Now everything works fine :)

Snapey's avatar

@janmoes everything fine except your project should not be in the public_html folder

Are you sure your .env file is secure?

janmoes's avatar

@Snapey All files/folders that are normally located in the /public folder are in /public_html. And all other files/folders, for example controllers/models/views/env are located in a a different folder. So I had to change 2 filepaths in the index.php. Is that the correct way for a shared hosting, or am I doing something wrong?

janmoes's avatar

@Snapey

/home/user_blablalba
	/my_project
	/some_other_folders
	/public_html

Out of my head it's a bit like this

janmoes's avatar

@bicicura Thanks! It's only a pain to update the website so now and often, my cpanel also doesn't have a CLI, and if it had a CLI, I'm not sure if it is still possible to run artisan commands with the way I uploaded the project?

Please or to participate in this conversation.