从php脚本运行git pull

AFR*_*FRC 10 php linux git permissions ssh

我正在使用Git,GitHub和SSH尝试Perfect Workflow,除了git pull从php 运行命令外,我已经完成了所有设置.

当我跑exec('git pull')我得到:

无法创建目录'/.ssh'.主机密钥验证失败.致命:远程端意外挂断

如果我在终端中运行它(作为root)它工作正常,但我需要这个钩子工作从Post-Receive URL(Github).

如果exec('whoami')我得到了apache.

这是来自medosmple与CentOS的(dv).

qui*_*tin 8

如果你希望apache(用户)能够从git中提取,你必须为apache创建一个ssh密钥,然后将其添加到github上的只读密钥.

流程是这样的(根据您的需求调整)

usermod -s /bin/bash apache
su apache
cd ~
ssh-keygen # work through the keygen dance (added a dash)
Run Code Online (Sandbox Code Playgroud)

上传(在这里指的是apache的homedir)~/.ssh/id_rsa.pub到github并给apache访问它需要从哪个repos拉出来.

然后你就可以再次测试服务器上的作"ing到Apache和运行的git拉

su apache
cd ~/working-copy
git clone my-project
Run Code Online (Sandbox Code Playgroud)

一旦它工作,你应该能够通过PHP 运行git pull.

  • 它是`usermod`,而不是`chmod`! (3认同)