我想做什么
我在位桶上有一个 git 存储库。从本地计算机推送到存储库后,我想自动将主分支拉到我的网络空间。
到目前为止我做了什么
我使用 ssh 连接到我的服务器,创建了 ssh 密钥并在 github 上注册了公钥。 我创建了一个.sh脚本,该脚本使用 ssh 拉取主分支 - 到目前为止,上帝 - 当我从命令行/腻子运行脚本时,一切正常
问题出在哪里
我想在 bitbucket 上使用 webhook 触发 .sh 脚本(我可以提供一个 url(。为此,我在我的网络空间中创建了一个.php文件:
<?php
$output = shell_exec('./deploy.sh 2>&1');
echo $output;
我的.sh脚本如下所示:
#!/bin/bash
git pull git@bitbucket.org:dualmeta/test.git master
如前所述,使用 putty 运行 .sh 脚本工作得很好。但是,如果我在浏览器中输入.php文件的 url,它会给我一个错误:
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
我已经做了一些研究,发现很多人都有完全相同的问题。但是,就我而言,我没有root/sudo访问权限,因为它是租用的网络空间,而不是我自己的虚拟服务器。
有机会让它工作吗?
您必须将访问 www-data 或 apache 用户添加到您的 git 目录中。
chown -R apache:apache git_directory
或
chown -R www-data:www-data git_directory
或
chmod o+rw -R git_directory
也使用这个:
git config credential.helper store