简体   繁体   English

错误:无法打开.git / FETCH_HEAD:使用php脚本进行git pull时权限被拒绝

[英]error: cannot open .git/FETCH_HEAD: Permission denied when using php script for git pull

I mad simple php script for git pull 我为git pull疯狂了简单的PHP脚本

<?php
$output = shell_exec("cd /var/www/domain.tld/html/test/ && git pull 2>&1");
echo "<pre>$output</pre>";

named it git.php and gave it 755 命名为git.php并给它755

the output was 输出是

error: cannot open .git/FETCH_HEAD: Permission denied

but when try from the terminal 但是当从终端尝试时

$ git pull
Already up-to-date.

i checked the directories ownership , my user is "savvy" 我检查了目录所有权,我的用户“很精明”

drwxrwsr-x  4 savvy savvy     4096 Jul 13 05:40 test

and the files inside 和里面的文件

$ ls -la test/
total 20
drwxrwsr-x 4 savvy savvy 4096 Jul 13 05:40 .
drwxr-xr-x 7 savvy savvy 4096 Jul 13 05:38 ..
drwxrwsr-x 8 savvy savvy 4096 Jul 13 05:41 .git
-rw-rwSr-- 1 savvy savvy   19 Jul 13 05:39 test.php

.git .git

$ ls -la .git/
total 60
drwxrwsr-x 8 savvy savvy 4096 Jul 13 05:41 .
drwxrwsr-x 4 savvy savvy 4096 Jul 13 05:40 ..
drwxrwsr-x 2 savvy savvy 4096 Jul 13 05:39 branches
-rw-rwSr-- 1 savvy savvy  268 Jul 13 05:39 config
-rw-rwSr-- 1 savvy savvy   73 Jul 13 05:39 description
-rw-rwSr-- 1 savvy savvy   97 Jul 13 05:41 FETCH_HEAD
-rw-rwSr-- 1 savvy savvy   23 Jul 13 05:39 HEAD
drwxrwsr-x 2 savvy savvy 4096 Jul 13 05:39 hooks
-rw-rwSr-- 1 savvy savvy  104 Jul 13 05:41 index
drwxrwsr-x 2 savvy savvy 4096 Jul 13 05:39 info
drwxrwsr-x 3 savvy savvy 4096 Jul 13 05:39 logs
drwxrwsr-x 4 savvy savvy 4096 Jul 13 05:39 objects
-rw-rwSr-- 1 savvy savvy   41 Jul 13 05:40 ORIG_HEAD
-rw-rwSr-- 1 savvy savvy  107 Jul 13 05:39 packed-refs
drwxrwsr-x 5 savvy savvy 4096 Jul 13 05:39 refs

~/.ssh 〜/ .ssh

drwx------ 2 savvy savvy 4096 Jul 13 04:56 .ssh

inside

$ ls -la .ssh/
total 36
drwx------ 2 savvy savvy 4096 Jul 13 04:56 .
drwxr-xr-x 4 savvy savvy 4096 Jul 12 08:34 ..
-rw-r--r-- 1 savvy savvy  398 Jul 12 05:46 authorized_keys
-rw-rw-r-- 1 savvy savvy   59 Jul 11 10:10 config
-rw------- 1 savvy savvy 1679 Jul 11 07:44 id_rsa
-rw-rw-r-- 1 savvy savvy  398 Jul 12 05:21 id_rsa.pub
-rw-r--r-- 1 savvy savvy 1768 Jul 13 05:08 known_hosts

I solve this problem by the following 我通过以下方法解决这个问题

1- copy /home/savvy/.ssh to /var/www/ 1-将/home/savvy/.ssh复制到/ var / www /

# cp -R /home/savvy/.ssh /var/www/

2- gave the /var/www diractory to www-data user 2-将/ var / www目录交给www-data用户

# chown -R www-data:www-data /var/www/

3- login as www-data user 3-以www-data用户身份登录

$ su
Password: 
# su -s /bin/bash www-data

4- clone the repo into my directory /var/www/domain.tld/html/test/ 4-将存储库克隆到我的目录/var/www/domain.tld/html/test/

5- call the git.php file i made already domain.tld/git.php 5-调用我已经创建的git.php文件domain.tld / git.php
result 结果

From bitbucket.org:repo/test
8e9f67c..185cd9e  master     -> origin/master
Updating 8e9f67c..185cd9e
Fast-forward
test.php | 1 +
1 file changed, 1 insertion(+)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM