shell_exec和git pull [英] shell_exec and git pull
问题描述
我希望有人可以帮忙,我有一个PHP页面,它使用 shell_exec
来压缩目录并运行 git pull
来关闭最近的资料库更改。
I was hoping someone could help, I have a PHP page which uses shell_exec
to zip up a directory and run git pull
to bring down recent repository changes.
$op = shell_exec("cd /home/user/git/$repo/$dir/; zip -r /home/user/archives/$dir.$datestamp.zip $dir; cd /home/user/git/$repo/$dir/; git pull");
这个zip工作正常。如果我将 git pull
更改为例如 git log
或 git status
- 在我的shell_exec中,这也适用,我可以看到日志文件。
The zip works fine. If I change git pull
to for example git log
or git status
- within my shell_exec, this works also, and I can see the log file.
只是似乎不喜欢git pull。
Just doesn't seem to like git pull.
我看到另一个类似的帖子,但wasn不知道它是如何实现的>> Shell_exec with git pull?
I saw another similar post to this, but wasn't sure how it was achieved >> Shell_exec with git pull?
推荐答案
从您在评论中的描述看来,问题在于您的 apache
用户无法写入存储库,这在使用 git pull
时显然是必需的。你有两个行动方案:
From your description in the comments it seems that the problem is that your apache
user cannot write to the repository, which is clearly required when you use git pull
. You have two courses of action:
- 设置Apache以作为另一个用户运行脚本(例如使用 suEXEC 在VirtualHost或通过用户目录)
- 更改存储库的权限,使
apache
用户可以写入它
- Setup up Apache to run the script as another user (e.g. using suEXEC either on a VirtualHost or via userdir)
- Change the permissions on your repository so the
apache
user can write to it
您应仔细考虑这两种选择的安全含义,但第二种选择可能最容易的。如果你还没有这样的团队,你可以用以下方式创建它:
You should think carefully about the security implications of either choice, but the second option is probably easiest. If you don't already have such a group, you can create it with:
addgroup gitwriters
...然后将自己和Apache用户添加到此组中:
... and then add yourself and the Apache user to this group:
adduser [yourusername] gitwriters
adduser apache gitwriters
<然后你可以按照另一个问题来更改存储库上的权限。重申以下几点细微差别:
Then you can follow the instructions in another question to change the permissions on the repository. To reiterate those with some slight variations:
# Recursively, set the group ownership of every file and directory of your repository:
chgrp -R gitwriters /path/to/your/repo
# Recursively, make every file and directory of your repository readable and writable
# by the group:
chmod -R g+rw /path/to/your/repo
# Recursively, set the setgid of every directory in the repository. The setgid bit
# on directories means that files created in the directory will have the same group
# ownership as the directory.
find /path/to/your/repo -type d -print0 | xargs -0 chmod g+s
然后希望你的 git pull
应该可以工作。
Then hopefully your git pull
should work.
这篇关于shell_exec和git pull的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!