Skip to content

Laravel storage link without SSH (and why it isn't working)

· The AYT team · 2 min read

Developer desk with two monitors, one showing code

The Laravel storage link is the symbolic link public/storage → storage/app/public, created with php artisan storage:link, which makes files saved on the public disk reachable at addresses like https://domain.com/storage/avatar.jpg. Without SSH, you run the command once through a cron job, through a temporary route with Artisan::call('storage:link'), or with a small PHP script that calls symlink(). If files still don't show, a common cause is an ordinary public/storage folder uploaded over FTP in place of the link.

What the Laravel storage link does

The Laravel documentation recommends keeping user-uploaded files that must be public (avatars, product images) in storage/app/public, with a symbolic link at public/storage pointing to that folder. The command reads the list in config/filesystems.php:

'links' => [
    public_path('storage') => storage_path('app/public'),
],

You can add more links to the same list; storage:link creates all of them. The command has two options: --force recreates existing links, and --relative uses relative paths (it needs the symfony/filesystem package).

How to run storage:link without SSH

Option 1: a cron job, run once

On your panel's Cron Jobs page, add a job that runs a minute from now:

cd /home/account/laravel && php artisan storage:link >> storage/logs/link.log 2>&1

Once it has run, read storage/logs/link.log in the File Manager and delete the job. This is the safest option, because it doesn't touch the application code.

Option 2: a temporary route

use Illuminate\Support\Facades\Artisan;

Route::get('/link-9f2c7e1a4b', function () {
    Artisan::call('storage:link');
    return Artisan::output();
});

Open the address once, then delete the route. Use a long random name and don't leave the route in the code: anyone who finds the address can run the command again.

Option 3: a PHP script with symlink()

A link.php file placed temporarily in public/:

<?php
symlink(__DIR__.'/../storage/app/public', __DIR__.'/storage');
echo 'done';

Open it in a browser once and delete it right away. It only works if your host hasn't disabled the symlink() function.

Why it isn't working (causes, most frequent first)

1. public/storage is a folder, not a link

FTP clients and many zip archives don't keep symbolic links: they copy their contents as an ordinary folder. The result: new files go to storage/app/public, but the browser looks in the old copy in public/storage. The command refuses to overwrite it and prints "The [public/storage] link already exists".

The fix: move the files from public/storage into storage/app/public (if there's anything there you don't have elsewhere), delete the public/storage folder and run storage:link again.

2. The link points to an old server

storage:link writes the absolute path (for example /home/old/laravel/storage/app/public). If you created the link locally or on another server and moved it along with the project, it points to a folder that doesn't exist. Delete it and create it again on the current server, or use php artisan storage:link --relative.

3. Files are saved on a different disk

Since Laravel 11, the default local disk has its root in storage/app/private. A Storage::put('photo.jpg', ...) with no disk given lands there, not in storage/app/public, so it isn't public. Save explicitly to the public disk:

$path = $request->file('avatar')->store('avatars', 'public');

4. Wrong APP_URL

Storage::url() builds the address from APP_URL followed by /storage. If APP_URL is http://localhost or contains /public, the generated links are wrong even though the file exists. Correct APP_URL in .env and clear the configuration cache.

5. The host doesn't allow or follow links

If symlink() is disabled, Laravel tries ln -s through exec(); if that's disabled too, the command fails. Separately, some servers refuse to follow symbolic links (on Apache, Options FollowSymLinks or SymLinksIfOwnerMatch matter; on nginx, disable_symlinks) and answer 403 for files under /storage. In both cases, ask support. As a link-free alternative, you can define a disk in config/filesystems.php whose root is directly in public_path('uploads').

6. The document root isn't public/

If the domain serves the project folder, the link is created in public/storage, but the /storage address leads elsewhere. Fix the public folder and document root first.

How to check the link works

  1. Upload a test file, for example test.txt, to storage/app/public.
  2. Open https://domain.com/storage/test.txt. If you see its contents, the link, the disk and the web server are all fine.
  3. If you get a 404, check in the File Manager whether public/storage is a link (not an ordinary folder) and which path it points to.
  4. If you get a 403, the server isn't following the link: see cause 5.

Delete the test file afterwards.

Frequently asked questions

Do I need to run storage:link after every deploy?

It depends on how you deploy. If you upload files over the same copy, the link stays. If every deploy creates a new folder (as release-based tools do, and as AYT does), the link has to be created in each new release, so the command belongs in the deploy script.

On AYT hosting

On AYT, every deploy from the Laravel Toolkit clones the repository into a new release (releases/...). The storage folder is a shared path: it stays the same across releases, so uploaded files aren't lost on deploy. The public/storage link, however, isn't in the repository (/public/storage is in Laravel's default .gitignore), so each new release needs it.

The fix is to add php artisan storage:link to the deploy script on the Deployments page. The default script, with the line added before optimize:

composer install --no-dev --prefer-dist --no-interaction --optimize-autoloader
if [ -f package.json ]; then if [ -f package-lock.json ]; then npm ci; else npm install; fi && npm run build && rm -rf node_modules; fi
php artisan migrate --force
php artisan storage:link
php artisan optimize

The Laravel Toolkit's Commands page for artisan commands

For the release running now, you can run storage:link once from the Commands page, which runs non-interactive artisan commands in the current release, for up to 120 seconds. From the next deploy on, the line in the script takes care of the link. Don't commit public/storage to the repository as a folder. More on deploying in Laravel on hosting without SSH; see also the supported apps and the plans.

More articles

All articles