從php腳本運行git pull

[英]Running git pull from a php script


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.

我正在使用Git,GitHub和SSH嘗試Perfect Workflow,除了從php運行命令git pull之外,我已經完成了所有設置。

When i run exec('git pull') i get:

當我運行exec('git pull')時,我得到:

Could not create directory '/.ssh'. Host key verification failed. fatal: The remote end hung up unexpectedly

無法創建目錄'/.ssh'。主機密鑰驗證失敗。致命:遠程端意外掛斷

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).

如果我在終端中運行它(作為root)它工作得很好,但我需要這個鈎子從Post-Receive URL(Github)工作。

If i do exec('whoami') i get apache.

如果我做exec('whoami')我會得到apache。

It's a (dv) from mediatemple with CentOS.

這是來自medosmple與CentOS的(dv)。

1 个解决方案

#1


8  

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.

如果你希望apache(用戶)能夠從git中提取,你必須為apache創建一個ssh密鑰,然后將其添加到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.

上傳(在這里指的是apache的homedir)〜/ .ssh / id_rsa.pub到github並給apache訪問它需要拉出的任何一個repos。

Then you can test on the server by again su'ing to apache and running the git pull

然后你可以再次通過apache和運行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。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2012/02/21/720a20be32552e9e75096ec30e6baa4e.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com