博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
通过php 执行git pull 自动部署
阅读量:6948 次
发布时间:2019-06-27

本文共 944 字,大约阅读时间需要 3 分钟。

hot3.png

安装git,生成公钥,加公钥 都有教程,需要注意的是以下几个方面

php以www用户执行,需要给到权限才能执行git pull

用合适的工具干合适的活,php去操作git pull只是在测试环境图方便搞的,如果正式环境,应该考虑用其他方式,例如系统定时任务设置触发条件等。

1、vim /etc/sudoers  

root下加一行

www localhost=(ALL) NOPASSWD:/usr/bin/git (安装git后目录用which git查看)

2、允许php执行exec shell_exec

3、改目录权限

4、.git改权限可写,我直接改成777了

5、.git/config https地址改成ssh的

password != "password") {    die("ERROR!"); // 判断密码}$fp = fopen("./log.txt", 'a');$lastcommit = $js->push_data->commits[count($js->push_data->commits) - 1]; // 获取最后的commitif (strstr($lastcommit->message, "release")) // 这里意为:如果最后的commit包含"release"则进行自动发布。{    exec("cd ./"); // 进入目录    exec("git pull origin master"); // 进行git拉取,前提是使用了ssh    fwrite($fp, "※" . date('Y-m-d H:i:s') . "\t" . $lastcommit->message . "\t" . $lastcommit->author->name . "\n"); // 进行记录} else {    fwrite($fp, date('Y-m-d H:i:s') . "\t" . $lastcommit->message . "\t" . $lastcommit->author->name . "\n");}

转载于:https://my.oschina.net/u/1987422/blog/477867

你可能感兴趣的文章
HashMap[转]
查看>>
面向对象程序设计——总结作业
查看>>
linux之 sed命令
查看>>
oracle rac的特征
查看>>
Linux之 find之 ctime,atime,mtime
查看>>
mysql查询
查看>>
Mongodb JAVA API
查看>>
记一些关于acm的小知识(自用,粗糙,勿点呀)
查看>>
【第40题】2019年OCP认证12C题库062考试最新考试原题
查看>>
创业难,守业更难
查看>>
2_C语言中的数据类型 (一)2.1.常量和字符串常量
查看>>
PHP程序员40点陋习
查看>>
how to remove untagged / none images
查看>>
CSS盒模型
查看>>
冒泡排序的实现和优化及其与插入,选择排序的比较
查看>>
Could not find modernizr-2.6.2 in any of the sources
查看>>
《浪潮之巅》读后感
查看>>
Lucene查询结果高亮
查看>>
python windows 远程执行bat
查看>>
补:关于man关于SEE ALSO(参见)中代号与vim下常用命令
查看>>