laravel symlink is changed when code is pushed to live site

萝らか妹 提交于 2019-12-10 11:05:46

问题


I am using laravel 5.5's storage symlink to store images. When I push code to the git and pull from live site then symlink path on live site becomes same as is on my local code . My local has this symlink

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

But live site expects this symlink path

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

Every time I have to delete symlink and create it again on live site. I have do these steps on live site

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

after doing these steps my symlink becomes according to live site and then it starts working. Live site should have this symlink

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

project_code/.gitignore :

public/storage

project_code/storage/app/.gitignore

 *
 !public/
 !.gitignore

How I can get rid of this issue.

Thanks in advance!


回答1:


As your symlink points to another location within the project directory structure, you can safely use relative path for link, instead of having absolute one (which is what artisan is setting up). That would require manual linking though (remove current link if you have it in app/public already):

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



回答2:


You might consider setting up a post-receive hook in the target Git repo (the one you are pushing to). See this one for instance.

In that hook, you can add any step you need (like fixing the symlink).



来源:https://stackoverflow.com/questions/46919060/laravel-symlink-is-changed-when-code-is-pushed-to-live-site

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!