shell_exec 和 git pull

发布于 2024-10-19 14:26:53 字数 584 浏览 5 评论 0 原文

我希望有人可以提供帮助,我有一个 PHP 页面,它使用 shell_exec 压缩目录并运行 git pull 来记录最近的存储库更改。

$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");

拉链工作正常。如果我将 git pull 更改为例如 git loggit status - 在我的 shell_exec 中,这也有效,并且我可以看到日志文件。

只是似乎不喜欢 git pull 。

我看到了另一篇与此类似的帖子,但不确定它是如何实现的>> 使用 git pull 执行 Shell_exec?

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");

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.

Just doesn't seem to like git pull.

I saw another similar post to this, but wasn't sure how it was achieved >> Shell_exec with git pull?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

好倦 2024-10-26 14:26:54

从评论中的描述来看,问题似乎是您的 apache 用户无法写入存储库,这在您使用 git pull 时显然是必需的。您有两个行动方案:

  1. 设置 Apache 以另一个用户身份运行脚本(例如使用 suEXEC 在 VirtualHost 上或通过 userdir
  2. 更改您的存储库的权限,以便 apache 用户可以对其进行写入。

您应该仔细考虑任一选择的安全含义,但第二个选项可能是最简单的。如果您还没有这样的组,则可以使用以下命令创建它:

addgroup gitwriters

...,然后将您自己和 Apache 用户添加到该组:

adduser [yourusername] gitwriters
adduser apache gitwriters

然后您可以按照 另一个问题以更改存储库的权限。重申一下那些略有不同的内容:

# 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 应该可以工作。

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:

  1. Setup up Apache to run the script as another user (e.g. using suEXEC either on a VirtualHost or via userdir)
  2. 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

... 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

Then hopefully your git pull should work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文