我有一个位于Bitbucket上的项目存储库。我将repo克隆到我的本地PC上进行操作。然后我推回到Bitbucket,然后我用putty连接到我的服务器并调用
git pull
并将更改拉到活动服务器。我从不从服务器推送。像这样一切都很好,但通过油灰连接到服务器来拉不是很方便。我在其中制作了一个小脚本"git_pull_script.sh",类似于:
git reset --hard
git clean -f
git pull
chown -f -R tdadmin *
...
没有什么问题。如果我在服务器上运行脚本
bash /home/tdadmin/git_pull_script.sh
一切都很顺利,做了我需要的事。为了澄清,git_pull_script设置了所有者和组tdadmin。
现在,为了让它对我来说更简单,我写了这个小小的php脚本。
<?php
exec('bash /home/tdadmin/git_pull_script.sh', $output);
print_r($output);
我认为应该这样做。所以我可以简单地打电话http://tddomain.com/pullscript.php
不幸的是,这不起作用。我做错了什么?
问题出在文件系统权限上。尽管已经更改了所有权限,".git"存储库文件夹仍保留在根所有者和组中。一旦我改变了这一点,一切都很好
也许找不到bash?这里有一个更简单的测试脚本来缩小
<?php
$output=array();
exec("bash --version",$output);
echo "bash:'n";print_r($output);
$output=array();
exec("/bin/bash --version",$output);
echo "/bin/bash:'n";print_r($output);
?>
另一个想法是:如果你的主机正在使用chroot或其他什么,可能找不到/home/tdadmin?尝试一个脚本来确认:
<?php
echo file_exists('/home/tdadmin/git_pull_script.sh')?"Yes":"no";
?>