doufei2194 2011-02-28 15:37
浏览 427
已采纳

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

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?

  • 写回答

1条回答

  • dongzhan1570 2011-02-28 20:25
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题