网站部署通过git的webhook
文章目录
<?php
/**
draguo
2016.1.9
通过git hook 自动化部署
在网站目录 mkdir hook
在hook中放置该文件用于接收hook请求
要在visudo 中添加
www-data ALL=(ALL) NOPASSWD: ALL
这里面有一个原则,就是apache 的运行用户要拥有执行脚本的权限,
因为权限的问题我出现了很多的问题,
ubuntu测试通过
修改/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);}
?>

评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论