Skip to content

Instantly share code, notes, and snippets.

@overtrue
Last active March 31, 2019 01:17
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save overtrue/0bf1cd704bf804de2e2c to your computer and use it in GitHub Desktop.
Save overtrue/0bf1cd704bf804de2e2c to your computer and use it in GitHub Desktop.
deploy.php
<?php
error_reporting(1);
$target = __DIR__ . '/../website.com'; // 生产环境web目录
$token = '您在coding填写的hook令牌';
$wwwUser = 'apache';
$wwwGroup = 'apache';
$json = json_decode(file_get_contents('php://input'), true);
if (empty($json['token']) || $json['token'] !== $token) {
exit('error request');
}
$repo = $json['repository']['name'];
$dir = __DIR__ . '/repos/' . $repo;
$cmds = array(
"cd $dir && git pull",
"rm -rf $target/* && cp -r $dir/* $target/",
"chown -R {$wwwUser}:{$wwwGroup} $target/",
);
foreach ($cmds as $cmd) {
shell_exec($cmd);
}
@laojiu
Copy link

laojiu commented Mar 26, 2016

我的系统是centos + nginx 为什么 web 访问的时候 shell_exec("whoami"); 返回的是apache用户 ? 我按照你的方式 使用了www 用户 不行哦

@costa92
Copy link

costa92 commented Feb 16, 2017

shell_exec('git pull') 无效,是什么原因呢?

@youmikuang
Copy link

超哥,我coding提交成功了。但是服务器上不更新。。怎么解决

@consatan
Copy link

rm -rf $target/* && cp -r $dir/* $target/

这命令不合适吧,如果 $target 里有 uploads 目录,或者文件比较多 rm 后等待 cp 时间较久,那不就 gg 了?
为啥不用 rsync ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment