Last active
March 31, 2019 01:17
-
-
Save overtrue/0bf1cd704bf804de2e2c to your computer and use it in GitHub Desktop.
deploy.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} | |
shell_exec('git pull') 无效,是什么原因呢?
超哥,我coding提交成功了。但是服务器上不更新。。怎么解决
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
我的系统是centos + nginx 为什么 web 访问的时候 shell_exec("whoami"); 返回的是apache用户 ? 我按照你的方式 使用了www 用户 不行哦