laravel 将代码推送到实时站点时,符号链接会更改

laravel symlink is changed when code is pushed to live site

我正在使用 laravel 5.5 的存储符号链接来存储图像。当我将代码推送到 git 并从实时站点拉出时,实时站点上的符号链接路径变得与我的本地代码相同。 我的本地有这个符号链接

 storage -> /home/path/to/project/app/public/ 

但实时站点需要此符号链接路径

 storage -> /var/www/html/website.com/public_html/project_code/storage/app/public/

每次我都必须删除符号链接并在实时站点上重新创建它。 我已经在实时网站上执行了这些步骤

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

完成这些步骤后,我的符号链接变为根据实时站点,然后它开始工作。 实时站点应该有这个符号链接

storage -> /var/www/html/website.com/public_html/project_code/storage/app/public/

project_code/.git忽略:

public/storage

project_code/storage/app/.git忽略

 *
 !public/
 !.gitignore

如何解决这个问题。

提前致谢!

例如,您可以考虑设置一个 post-receive hook in the target Git repo (the one you are pushing to). See this one

在该挂钩中,您可以添加任何需要的步骤(例如修复符号链接)。

由于您的符号链接指向同一项目中的另一个位置,因此您可以在链接时安全地使用相对路径,而不是绝对路径(artisan 正在设置)。不过这需要手动链接:

cd app/public
ln -s ../storage/app/public storage

如果已有 storage 符号链接,请先删除它。