从 php 脚本运行 git pull
我正在尝试 完美的工作流程,使用 Git、GitHub 和 SSH,除了从 php 运行命令 git pull
外,我已经设置好了一切.
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.
当我运行 exec('git pull')
我得到:
无法创建目录/.ssh".主机密钥验证失败.致命:远端意外挂断
Could not create directory '/.ssh'. Host key verification failed. fatal: The remote end hung up unexpectedly
如果我在终端(以 root 用户身份)运行它,它工作得很好,但我需要这个钩子从接收后 URL (Github) 工作.
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).
如果我执行 exec('whoami')
我得到 apache
.
If i do exec('whoami')
i get apache
.
它是来自带有 CentOS 的 mediatemple 的 (dv).
It's a (dv) from mediatemple with CentOS.
推荐答案
如果您希望 apache(用户)能够从 git 中拉取数据,您必须为apache,然后将其添加到 github 上的只读键中.
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)
usermod -s /bin/bash apache
su apache
cd ~
ssh-keygen # work through the keygen dance (added a dash)
上传(这里的波浪号指的是 apache 的 homedir)~/.ssh/id_rsa.pub
到 github 并授予 apache 访问它需要从中提取的任何存储库的权限.
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.
然后您可以通过再次su到apache并运行git pull
Then you can test on the server by again su'ing to apache and running the git pull
su apache
cd ~/working-copy
git clone my-project
一旦成功,您应该能够通过 PHP 运行 git pull.
Once that's working you should be able to run a git pull through PHP.
相关文章