簡體   English   中英

shell_exec和git pull

[英]shell_exec and git pull

我希望有人可以提供幫助,我有一個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。

我看到了另一個類似的帖子,但是不確定它是如何實現的>> Shell_exec with git pull?

根據您在注釋中的描述,問題似乎是您的apache用戶無法寫入存儲庫,這在使用git pull時顯然是必需的。 你有兩個行動方案:

  1. 設置Apache以另一個用戶身份運行腳本(例如, 在VirtualHost上或通過userdir使用suEXEC
  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應該有效。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM