2011-02-28 164 views
1

我希望有人可以幫忙,我有一個PHP頁面,它使用shell_exec來壓縮一個目錄並運行git pull來降低最近的存儲庫更改。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拉。

我看到了另一個類似的帖子這一點,但不知道它是怎麼實現>>Shell_exec with git pull?

+0

'git pull'的輸出是什麼?你有沒有試過'git pull origin master'或者你的分支/遙控器的名字是什麼? – Artefact2 2011-02-28 15:45:32

+0

你好...'git pull'不會遺漏任何東西,'git pull origin master'也不會 - 很奇怪。 – williamsowen 2011-02-28 15:50:05

+0

您提到的另一個問題的答案是存在權限問題,這似乎是合理的,因爲'git log'和'git status'不需要寫入存儲庫,而'git pull'會。爲了研究這一點,我會將你的'git pull'改爲'touch/tmp/whatever',然後使用'ls -l/tmp/whatever'來找到擁有這個文件的用戶和組 - 這會告訴你用戶是什麼'shell_exec'命令正在運行。如果你不能以該用戶的身份寫入存儲庫目錄,那麼這就可以解釋爲什麼'git pull'失敗...... – 2011-02-28 16:05:44

回答

4

從你的描述中看來,問題是,你的apache用戶不能寫入倉庫的意見,這在使用git pull時顯然是必需的。你有兩項行動:

  1. 安裝Apache才能運行該腳本作爲另一個用戶(例如,使用suEXEC要麼on a VirtualHost or via userdir
  2. 變化你的資料庫中的權限,這樣apache用戶可以寫入

您應該仔細考慮任一選擇的安全影響,但第二種選擇可能是最簡單的。如果你還沒有這樣一個小組,你可以創建它:

addgroup gitwriters 

...然後自己和Apache用戶添加到該組:

adduser [yourusername] gitwriters 
adduser apache gitwriters 

然後你就可以按照another question中的說明更改存儲庫的權限。重申那些有一些細微的變化:

# 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應該工作。

+0

乾杯標記爲您提供幫助。我已經按照你說的話, 目前我有這樣的: 'IP-XX-XXX-XX-XXX〜:ID阿帕奇 的uid = 48(阿帕奇)GID = 48(阿帕奇)組= 48(阿帕奇) ,10(wheel),501(gitwriters)' 然而,當執行'git pull'時,它仍然在Apache組下運行。是否有辦法改變默認組 - 如果有意義!對於這一切頗爲新鮮的道歉,再次歡呼。 – williamsowen 2011-03-01 12:11:23

+0

@williamsowen:是的,如果你遵循方法2,你不會改變PHP代碼運行的用戶,你只是讓該用戶(以及你平常的用戶帳戶)能夠寫入存儲庫。你確實需要讓它作爲一個不同的用戶來運行嗎?如果是這樣,你需要看看方法1。 – 2011-03-01 12:22:40