Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

laojiu commented Mar 26, 2016

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

@costa92

This comment has been minimized.

Copy link

costa92 commented Feb 16, 2017

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

@Chasers9527

This comment has been minimized.

Copy link

Chasers9527 commented Jun 26, 2017

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

@consatan

This comment has been minimized.

Copy link

consatan commented Jan 17, 2019

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
You can’t perform that action at this time.