从 php 脚本运行 git pull
我正在尝试 完美的工作流程,使用 Git、GitHub 和 SSH,除了从 php 运行命令 git pull
之外,我已完成所有设置。
当我运行 exec('git pull') 时,我得到:
无法创建目录“/.ssh”。主机密钥验证失败。 fatal:远端意外挂断
如果我在终端(以 root 身份)运行它,它工作得很好,但我需要这个钩子才能从接收后 URL (Github) 工作。
如果我执行exec('whoami')
,我会得到apache
。
这是来自 mediatemple 的 CentOS 的 (dv)。
I was trying the Perfect Workflow, with Git, GitHub, and SSH, and i have everything set up, except running the command git pull
from php.
When i run exec('git pull')
i get:
Could not create directory '/.ssh'. Host key verification failed.
fatal: The remote end hung up unexpectedly
If i run it in the terminal (as root) it works just fine, but i need this hook to work from the Post-Receive URL (Github).
If i do exec('whoami')
i get apache
.
It's a (dv) from mediatemple with CentOS.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您希望 apache(用户)能够从 git 拉取,则必须为 apache 创建一个 ssh 密钥,然后将其添加到 github 上的只读密钥中。
流程是这样的(根据您的需求进行调整)
上传(这里的波浪号指的是 apache 的 homedir)
~/.ssh/id_rsa.pub
到 github 并授予 apache 访问它需要从中提取的任何存储库的权限。然后,您可以通过再次su'ing到apache并运行git pull来在服务器上进行测试
一旦工作正常,您应该能够运行git pull
If you want apache (the user) to be able to pull from git, you'll have to create an ssh key for apache, then add that to the read only keys on github.
The flow is something like this (tweak to your needs)
Upload (tilde here refers to apache's homedir)
~/.ssh/id_rsa.pub
to github and give apache access to whichever repos it needs to pull from.Then you can test on the server by again su'ing to apache and running the git pull
Once that's working you should be able to run a git pull through PHP.