码云 php webhook,利用webhook 实现自动化部署 【PHP版本】

1、先git clone 代码

2、配置nginx,域名绑定到代码目录

3、在代码目录创建 webhook.php (随意命名)

$pwd = getcwd();

$command = 'cd ' . $pwd . ' && git pull 2>&1'; // 2>&1 是输出错误,有利于调试

$output = shell_exec($command);

file_put_contents('./webhook.log', $output);// 输出内容保存到日志,需要注意日志文件要有足够的权限

print $output;

?>

4、配置码云webhook,url为 http://yourdomain/webhook.php

5、碰到问题了:git pull 需要输入账号密码

解决办法:

执行git config --global credential.helper store命令

然后git push origin your-branch       // your-branch就是分支的名字

//会让你输入用户名和密码,就会保存起来,下次就不需要了

6、创建密钥

$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

Enter a file in which to save the key (/c/Users/you/.ssh/id_rsa):[Press enter] // 这里填写 /home/www/.ssh/id_rsa,因为nginx用户组是www,之后一路回车

$ eval $(ssh-agent -s)

$ ssh-add /home/www/.ssh/id_rsa

之后就复制 /home/www/.ssh/id_rsa_pub里面的内容,添加到码云->设置->SSH公钥里面

注意:/home/www/.ssh 目录用户组:用户需要设置为, chown -R www:www /home/www/.ssh

Git 常见问题解决

Your local changes to the following files would be overwritten by merge: index1.html Please, commit your changes or stash them before you can merge

在服务器上可以直接执行退回上一个版本,再拉取代码(因为没人会在服务器开发,代码都在码云,不担心没了)

git reset --hard

git pull origin your-branch

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值