<?php /**
draguophp
2016.1.9linux
经过git hook 自动化部署git
在网站目录 mkdir hookweb
在hook中放置该文件用于接收hook请求shell
要在visudo 中添加apache
www-data ALL=(ALL) NOPASSWD: ALLjson
这里面有一个原则,就是apache 的运行用户要拥有执行脚本的权限,ubuntu
由于权限的问题我出现了不少的问题,centos
ubuntu测试经过less
修改/etc/selinux/config 文件
将SELINUX=enforcing改成SELINUX=disabled
centos 测试经过php >5.3
*/
ini_set('max_execution_time', '0');
// 生产环境目录
$web_dir = __DIR__.'/../casarover';
// 准备部署的文件
$dir = '/var/www/casarover';
// hook password
$pwd = '这个是密码的部分';
// 接收hook
$data = $_POST["hook"];
$json = json_decode($data,true);
(empty($json)) {
header("Location: http://www.draguo.cn");
}
($json['password'] !== $pwd) {
echo "password is wrong"; exit();
}
// 执行的脚本内容
$shs = array(
"cd $dir && sudo git pull", "sudo rm -rf $web_dir/* ", "cd $dir/web && sudo rm -rf .settings/ docs/ tests/ .buildpath .project .zfproject.xml website/less/ ", "sudo cp -r $dir/web/* $web_dir/" );
($shs as $sh) {
echo $sh; echo "<br>"; shell_exec($sh);
}
?>