3
votes

I am new in Laravel, as you know in order to access stored files you should have a symlink from storage/app/public to public/storage. In computer you can just type in command line: php artisan storage:link. But now I have deployed my website on hosting and want to create a symlink. How can I do it?

4
Is it a shared hosting?Victor Anuebunwa

4 Answers

0
votes

I'm afraid this is near impossible on shared hosting since you would need a shell access to create the same symlink like on your computer.

Depending on your options maybe Laravel Forge is helpful to you.

Kind regards

0
votes

Maybe if you can add in the "scripts" tag of your composer a call to create the link after the deploy of your project:

composer.json file:

"scripts": {
    "post-root-package-install": [
        "php -r \"file_exists('.env') || copy('.env.example', '.env');\""
    ],
    "post-create-project-cmd": [
        "php artisan key:generate"
    ],
    "post-install-cmd": [
        "Illuminate\\Foundation\\ComposerScripts::postInstall",
        "php artisan optimize"
        "php artisan storage:link"
    ],
    "post-update-cmd": [
        "Illuminate\\Foundation\\ComposerScripts::postUpdate",
        "php artisan optimize"
        "php artisan storage:link"
    ]
}

This will cause the link to be created every time a **composer update** or **composer install** call occurs.

If the storage folder is not created, you will receive:

The [public / storage] directory has been linked.

If it is already created:

The "public / storage" directory already exists.

See also this discussion that may help you: https://github.com/laravel/internals/issues/34

0
votes

Cron job does the trick for me on shared hosting. Simply configure cron job to run the command the next minute (or a specific close time), and delete it after.

For example, this will run the command at 9:30am and log any output to myjob.log

30 9 * * * /path/to/php /path/to/artisan storage:link >> /path/to/myjob.log 2>&1
0
votes

Just create a symlink in a php file and upload it to your public folder then navigate to it through your browser. The links must be absolute path....

$targetFolder = '/home/account_name/laravel/storage/app/public';

$linkFolder = '/home/account_name/public_html/storage';

symlink($targetFolder, $linkFolder);

echo 'Done!'

Lets save the file as link.php and upload it then navigate to it via http://your_site.com/link.php