如何实现本地git push之后服务器自动更新
首先搭建好仓库之后,在服务器进行拉取,服务器配置好ssh,能在命令中执行git pull成功,然后通过写PHP脚本增加webhook地址来实现自动更新。
auto.php 的内容如下:
<?php $pull = '"C:\Program Files\Git\cmd\git.exe" pull 2>&1'; exec($pull,$out); foreach($out as $v) { echo iconv( 'GB2312','UTF-8', $v)."<br>"; } ?>
浏览器中运行脚本文件,会报一下错误:
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.
原因是Apache默认使用的是本地的系统账户登录,修改Apache登录账户与服务器上使用账户,
重启Apache,然后设置webhook
Comments (0)