-
配置gitlab
- php 代码
在根目录下创建webhook.php 文件
<?php
$auth = "1234";// 此配置和token一直,用于验证
$path = "/var/www/html";
$token = $_SERVER['HTTP_X_GITLAB_TOKEN'];
$input = file_get_contents("php://input");
$data = json_decode($input, true);
if ($auth == $token && $data['ref'] == "refs/heads/dev" && $data['total_commits_count']>0) {
$res = shell_exec("cd {$path} && git pull origin dev");
file_put_contents("/var/www/html/web.log",$res);
} else {
file_put_contents("/var/www/html/web.log");
}
- 修改用户权限
- 因为运行php的用户是nginx(自己配置的), 所以要把nginx 用户的ssl公钥放到gitlab SSH 密钥.
2 . 根目录下,nginx 要有读写权限,特别是.git 目录下的写权限
cd .git/objects/
chown -R nginx:nginx ./