Laravel Storage Link Shared Hosting

Our Laravel Storage Link Shared Hosting starts at $7.99/month and includes PHP and MySQL databases, unlimited WordPress installations, a free domain name, a cPanel control panel, 10GB of storage space, and much more.

Laravel Storage Link Shared Hosting

Method 1

This is very simple method and frequently used by me and other many developers when they upload Laravel project on Shared Hosting. Just add some line code in routes/web.php file

Basic to Advance Routing in Laravel

PHP

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

then save your file and open your domain with symlink url.

example – http://example.com/symlink

It will automatically create a linked storage folder in your public directory.

After that you can delete the above code.

Method 2

Using this method you have two choice where you can select anyone which is more comfortable for you.

Choice One – Create File in Public Folder

you can create file with any name except that exist before. For Example symlink.php is perfect name. Here we will use symlink() function that available in php core so you don’t need to create own functions.

PHP

 <?php
$target =$_SERVER['DOCUMENT_ROOT'].'/storage/app/public';
$link = $_SERVER['DOCUMENT_ROOT'].'/public/storage';
symlink($target, $link);
echo "Done";
?> 

After that just open you domain with symlink.php url in browser.

For Example – http://example.com/symlink.php

After complete Just delete symlink.php file from public folder.

Choice Two – Create new Route in web.php

As i told you above that is a choice you can select one or two its depend on you.

PHP

Route::get('/symlink', function () {
   $target =$_SERVER['DOCUMENT_ROOT'].'/storage/app/public';
   $link = $_SERVER['DOCUMENT_ROOT'].'/public/storage';
   symlink($target, $link);
   echo "Done";
});

After that just open you domain with symlink url in browser.

For Example – http://example.com/symlink

After complete Just remove the route and you ready to go

laravel storagelink not working

Create a symbolic link

Alternatively, you can also try fixing the issue without the need for SSH to the server. For Laravel 5 and above, you can use the Artisan :: call() method on the route or controller to execute Artisan commands without using a terminal. First, go to the route folder your-app-folder/routes/web.

Leave a Comment