Search code examples
phplaravellaravel-5sshserver

L5.5 Create symlink between storage and public directories on shared hosting using SSH


I've setup my production server on a shared hosting my directory structure looks like this (my project is placed at same level as public):

/home/user/my-laravel-project/
/home/user/public_html

This is how I'm storing my data in Storage > Public Disc

$data->store('path/to/data', 'public');

On production, using SSH, when I run this command php artisan storage:link. It creates a symlink between storage/app/public and my-laravel-project/public I want this link to be created between storage/app/public and /home/user/public_html

What I've tried

  • Tried removing my-laravel-project/public then tried php artisan storage:link .. it failed with an error No file or directory
  • I tried changing storage path from storage_path('app/public) to public_path() under config/filesystem.php but no success
  • I've also tried to create symlink using shell command ln -nsf /home/user/my-laravel-project/storage/app/public /home/user/public_html but no success

Tried many other little tweaks but nothing works for me .. I'm looking for a proper solution to create a symlink between storage/app/public and /home/user/public_html on my shared server

Note I don't want to change paths in config/filesystems.php as that's not a proper solution

My current server is setup on Siteground with php version 7.0.32 and Laravel 5.5.43


Solution

  • If you want to create defaults symlinks you should create one for yourself.

    This is the symlink pattern:

    ln -s target source
    

    So in your case you have to do following:

    ln -s /home/user/public_html storage/app/public