当前位置:Gxlcms > PHP教程 > 关于github使用webhook部署代码的问题?

关于github使用webhook部署代码的问题?

时间:2021-07-01 10:21:17 帮助过:15人阅读

使用PHP处理github发送过来的请求,测试正常。在调用脚本或使用exec()执行命令总是不能成功。

// 判断签名是否匹配
if ($hash === $payloadHash) {
    // 调用shell
    // file_put_contents('/var/www/niucunhui.io/auto/test.txt', '程序走到这里了');
    exec('cd /var/www/niucunhui.io/auto/ && git pull');
}

file_put_contents可以写入内容,证明签名是匹配成功的。在服务器单独执行脚本,也是可以pull代码。

脚本如下:

#!/bin/bash

WEB_PATH='/var/www/niucunhui.io/sql-optimize-referance/'
WEB_USER='www'
WEB_USERGROUP='www'

echo "Start deployment"
cd $WEB_PATH
echo "pulling source code..."
git reset --hard origin/master
git clean -f
git pull
git checkout master
echo "changing permissions..."
chown -R $WEB_USER:$WEB_USERGROUP $WEB_PATH
echo "Finished."

单独写一个PHP程序 exec()命令也是可以执行的。

请问,还有可能是那里的问题?
服务器版本 CentOS 6.5
PHP版本 5.6.15

回复内容:

使用PHP处理github发送过来的请求,测试正常。在调用脚本或使用exec()执行命令总是不能成功。

// 判断签名是否匹配
if ($hash === $payloadHash) {
    // 调用shell
    // file_put_contents('/var/www/niucunhui.io/auto/test.txt', '程序走到这里了');
    exec('cd /var/www/niucunhui.io/auto/ && git pull');
}

file_put_contents可以写入内容,证明签名是匹配成功的。在服务器单独执行脚本,也是可以pull代码。

脚本如下:

#!/bin/bash

WEB_PATH='/var/www/niucunhui.io/sql-optimize-referance/'
WEB_USER='www'
WEB_USERGROUP='www'

echo "Start deployment"
cd $WEB_PATH
echo "pulling source code..."
git reset --hard origin/master
git clean -f
git pull
git checkout master
echo "changing permissions..."
chown -R $WEB_USER:$WEB_USERGROUP $WEB_PATH
echo "Finished."

单独写一个PHP程序 exec()命令也是可以执行的。

请问,还有可能是那里的问题?
服务器版本 CentOS 6.5
PHP版本 5.6.15

https://zhuzhenyu.org/2016/01/03/php-github-php/

git命令需要写全路径

人气教程排行