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

louis12's avatar

Error when trying to create a symlink on server.

Good day,

I have been trying to create a symlink between the storage/app/public folder and the storage folder that are located in the public_html directory. I am currently making use of a shared hosting plan and currently do not have access to a terminal on the server. I have tried to create a symlink by executing the below route, but are receiving the error:

ErrorException symlink(): No such file or directory

Route::get('/foo', function () {
    Artisan::call('storage:link');
});

Any assistance would be appreciated.

0 likes
7 replies
Snapey's avatar
Snapey
Best Answer
Level 122

You cannot use the artisan command as your public folder is not called public

You will need to create your own symlink using exec

louis12's avatar

@snapey Thank you for your reply. I have tried to create a link by executing the below code. It creates a link in the public_html folder called "storage", but the images that are stored in the path: homedirectory/findingproperty/storage/app/public/cover_images are still not displaying on the front end. I am not sure whether the target folder path and the link folder path in the code are set correct though.

<?php

$targetFolder = $_SERVER['DOCUMENT_ROOT'].'/storage/app/public';
$linkFolder = $_SERVER['DOCUMENT_ROOT'].'/storage';
symlink($targetFolder,$linkFolder);
echo 'Symlink process successfully completed';

?>
MichalOravec's avatar

@louis12 Try this

<?php

$targetFolder = $_SERVER['DOCUMENT_ROOT'].'/storage/app/public';
$linkFolder = $_SERVER['DOCUMENT_ROOT'].'/public/storage';
symlink($targetFolder,$linkFolder);
echo 'Symlink process successfully completed';

?>

Because storage should be in public folder.

louis12's avatar

@michaloravec Thank you for the reply. I have executed the suggested code. A link called "storage" was created in: homedirectory/public_html/public, but the images still doesn't display on the front end. The path to the images in the blade view are:

src="/storage/cover_images/{{$property->cover_image}}"

The images does however display on the front end when manually placing them in the directory: homedirectory/public_html/storage.

Snapey's avatar

If your laravel project is in the folder homedirectory then;

<?php

$targetFolder = base_path() . '/storage/app/public';
$linkFolder = base_path() . '/public_html/storage/';
symlink($targetFolder,$linkFolder);
echo 'Symlink process successfully completed';

?>
louis12's avatar

@snapey Thank you! It worked after executing the script below:

<?php

$targetFolder = '/home2/property/findingproperty/storage/app/public';
$linkFolder = '/home2/property/public_html/storage';
symlink($targetFolder,$linkFolder);
echo 'Symlink process successfully completed';

?>
shanmostes3's avatar

But I should admit, the web editor freaks me out a piece based on the amount of internet site in production I noticed with the debug enabled :o

Please or to participate in this conversation.