Running git pull from a php script(从 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.
这篇关于从 php 脚本运行 git pull的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从 php 脚本运行 git pull
基础教程推荐
- 如何替换eregi() 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
