laravel symlink is changed when code is pushed to

2019-05-27 11:29发布

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!

2条回答
家丑人穷心不美
2楼-- · 2019-05-27 12:17

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
查看更多
兄弟一词,经得起流年.
3楼-- · 2019-05-27 12:17

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).

查看更多
登录 后发表回答