您好,欢迎访问一九零五行业门户网

使用PHP自动部署GIT代码,php部署git_PHP教程

使用php自动部署git代码,php部署git最近在使用coding的代码托管,顺便设置了webhook自动部署,过程还是挺艰辛的,主要还是没搞懂linux的权限控制,不过好在弄好了,分享一下获益最深的一篇文章,供大家参考,原文是英文版的,我的英语也不行,勉强能看懂,大家凑合着看吧
原文链接:http://jondavidjohn.com/git-pull-from-a-php-script-not-so-simple/
i intended to set up a repository (hosted on bitbucket) to initiate a pull on a dev server when new commits are pushed up.
it seemed like a simple enough process. bitbucket has a service that will fire off a post request as a post-receive hook. so i set up a receiving php script to check a randomized token and then initiate the git pull. looking something like this...
&1 at the end of your command.
after i realized this i logged in and found the full path of the git binary with which git, which is /full/path/to/bin/git.
&1);...
now it was reporting the next issue...
permissionserror: cannot open .git/fetch_head: permission denied
the apache user also needs read and write access to the entire repository.
chown -r ssh_user:www repository/
it's also a good idea to make sure any files/directories inherit this ownership if being created by others by setting the group sticky bit.
chmod -r g+s repository/
host key verification failednext, you need to do an intial git pull with the apache user to make sure the remote is added to the apache user's known_hosts file
sudo -u www git pull
ssh keyanother consideration created by this command being run by the apache user is the ssh key it uses to communicate with the remote repository.
first, i went down the path of attempting to use the git_ssh environment variable to set the ssh -i option to tell it to use a specific ssh key i had generated with the ssh user. i never got this to work, most likely because there are a lot of rules ssh uses to determine the safety of a given key. it requires some specific permissions regarding the user that is attempting to use the key.
an easier way i discovered was to give the apache user a home directory (via /etc/passwd) and a .ssh directory and then run the ssh-keygen command as the apache user (www)
sudo -u www ssh-keygen -t rsa
this creates the keys and puts them in their expected location with the proper permissions applied.
then i added the key as a read-only key for the bitbucket repository and everything worked as expected.

http://www.bkjia.com/phpjc/1053799.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/1053799.htmltecharticle使用php自动部署git代码,php部署git 最近在使用coding的代码托管,顺便设置了webhook自动部署,过程还是挺艰辛的,主要还是没搞懂linux的权限...
其它类似信息

推荐信息