从php脚本运行git pull [英] Running git pull from a php script

查看:91
本文介绍了从php脚本运行git pull的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Git,GitHub和SSH完美工作流程,除了运行 git pull 命令外,从php。



当我运行 exec('git pull')我得到:


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

如果我在终端(以root身份)运行它,它工作得很好,但我需要这个钩子从Post-Receive URL(Github)工作。



如果我做 exec('whoami')

code>我得到 apache



这是CentOS中的一个(dv)中介。

解决方案

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



流程如下所示(根据需要调整)

  usermod -s / bin / bash apache 
su apache
cd〜
ssh-keygen#通过上传(在这里代表指向apache的homedir) $> b
$ b

>〜/ .ssh / id_rsa.pub 给github,并给予Apache访问它需要从哪个回收站取消。



然后哟你可以在服务器上再次测试一下 su '到apache并运行 git pull

  su apache 
cd〜/ working-copy
git clone my-project

运行后,您应该可以通过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.

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.

解决方案

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)

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

su apache
cd ~/working-copy
git clone my-project

Once that's working you should be able to run a git pull through PHP.

这篇关于从php脚本运行git pull的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆