- 在github的setting里面的webhooks里把我们的url地址填进去。
- 钩子更新的代码如下:
<?php error_reporting(E_ALL); $gitPost = json_decode(file_get_contents("php://input")); $dir = '/home/www/ownShop';//该目录为git检出目录 $comm = "cd $dir && git checkout master && git pull origin master && git reset --hard && cd /home/www/ownShop/application && ln -f config_product.php config.php && ln -f database_product.php database.php 2>&1"; $handle = popen($comm, 'r'); $read = stream_get_contents($handle); echo "'$handle'; " . gettype($handle) . "\n"; pclose($handle); echo json_encode($read); ?>
主要代码其实来源PHP手册。之所以做输出,是为了在github控制面板能清楚看到在钩子生效钱是都是什么问题,需要根据webhooks传值记录日志的,根据接受值自行处理一下。
注:注意项目目录权限已经所属
如果做软连接的时候出问题,有可能是因为没有连接文件