Laravel - How to revert local storage symlink and refresh

前端 未结 4 1529
隐瞒了意图╮
隐瞒了意图╮ 2021-02-05 16:20

When I save images to storage they show in the storage/app directory, but they don\'t show in public/storage. I also noticed that a sto

4条回答
  •  遥遥无期
    2021-02-05 17:04

    I had this problem and I fixed it by adding this to my deployment script:

    cd public
    rm storage
    cd ..
    php artisan storage:link
    

    Before you do that, you can SSH into your deployment server and navigate to the /public folder. You might see a storage folder in there, and you should notice it's a symlink. You should leave it there and add my above commands to your deployment script.

    If you remove storage link manually, you'll need to skip these on the first deployment:

    cd public
    rm storage
    cd ..
    

    Then every deployment after, you can do:

    cd public
    rm storage
    cd ..
    php artisan storage:link
    

    If you don't do that, your deployment will fail probably because if rm storage throws an error, it will fail the build. Pay close attention to what I'm saying. You must be very specific when doing CLI commands, unless you can add some bash script that handles the 2 cases where ./public/storage exists (1) and when it doesn't (2).

    You might gloss over my mention about deleting the storage symlink reference manually, but don't forget that if you deployment script does it and then fails for another reason, the symlink will be gone.

    Someone should post an answer that uses a bash script to ensure both cases can be handled. I don't have the skill for that.

    NOTE: php artisan storage:link only works while you are in the root directory of your project. That's why my above script starts with cd public and why it does cd ... If you aren't in the root at the time, the php artisan command will fail.

提交回复
热议问题