我正在尝试 Perfect Workflow, with Git, GitHub, and SSH ,除了从 php 运行命令 git pull
之外,我已经设置好了所有内容。
当我运行 exec('git pull')
我得到:
Could not create directory '/.ssh'. Host key verification failed. fatal: The remote end hung up unexpectedly
如果我在终端(以 root 身份)运行它,它工作得很好,但我需要这个钩子(Hook)从 Post-Receive URL (Github) 工作。
如果我执行 exec('whoami')
我会得到 apache
。
这是来自 mediatemple with CentOS 的 (dv)。
最佳答案
如果您希望 apache(用户)能够从 git 中提取数据,您必须为 apache 创建一个 ssh key ,然后将其添加到 github 上的只读 key 中。
流程是这样的(根据您的需要调整)
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 访问它需要从中提取的任何 repos。
然后您可以通过再次su'ing 到apache 并运行git pull
在服务器上进行测试su apache
cd ~/working-copy
git clone my-project
一旦成功,您应该能够通过 PHP 运行 git pull。
关于php - 从 php 脚本运行 git pull,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9370975/