php - 从 php 脚本运行 git pull

标签 php linux git permissions ssh

我正在尝试 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/

相关文章:

linux 命令 xargs : maximum size of the arguments passed by it?

git - 如何从命令行在组织下创建 GitHub 存储库?

git - 如何查看提交中的文件内容——比如 `git show`

git - 我的 git 分支怎么忘记了它的父分支?

php - 如何在PHP复制时发送登录信息

php - 如何在laravel 5.8中合并两个sql表

linux - 使用标准输入将一些十六进制字符串放入 xxd 不会生成任何输出

r - 如何列出和选择旧版本的 R

php - 我将如何构造一个 mysql 查询来使用多个 AND 运算符?

php - 可以使用 GD 和 PHP 为透明图像添加背景颜色