10

I am currently setting up some git repositories on a Ubuntu LTS 14.04 machine with Apache 2.4.7.

This is the apache config:

SetEnv GIT_PROJECT_ROOT /var/www/html/git
SetEnv GIT_HTTP_EXPORT_ALL 1
SetEnv REMOTE_USER $REDIRECT_REMOTE_USER
ScriptAliasMatch \
    "(?x)^/git/(.*/(HEAD | \                                                                                                                             
                    info/refs | \                                                                                                                        
                    objects/(info/[^/]+ | \                                                                                                              
                             [0-9a-f]{2}/[0-9a-f]{38} | \                                                                                                
                             pack/pack-[0-9a-f]{40}\.(pack|idx)) | \                                                                                     
                    git-(upload|receive)-pack))$" \                                                                                                      
    /usr/lib/git-core/git-http-backend                                                                                                                   

<Location /git/oswald.git>
 Options +ExecCGI
 AuthType Basic
 DAV on
 AuthName "Git"
 AuthUserFile /etc/apache2/git_paragon_passwd
 Require valid-user

    Order allow,deny
    Allow from all
</Location>

The test repository is under /var/www/html/git/oswald.git. In the repository I have set the config property

http.receivepack=true

The file git-daemon-export-ok is present.

If I now try to clone with:

git clone https://server/git/oswald.git

after authentication I get:

fatal: https://server/git/oswald.git/info/refs not valid: is this a git repository?

(git 2.1.0 client, on the server git 1.9.1).

I tried several things, so if I don't use git-http-backend and go via WebDAV I can clone but not push, with git-http-backend I cannot even clone.

If I change the last line of ScriptAliasMatch from

/usr/lib/git-core/git-http-backend

to

/usr/lib/git-core/git-http-backend/$1

as stated in the man page of git-http-backend, I get

fatal: repository 'https://server/git/oswald.git/' not found

with the error.log from Apache:

AH00130: File does not exist: /usr/lib/git-core/git-http-backend/oswald.git/info/refs

Does anybody have an idea what is wrong? I have already spent a lot of time going through forums, but no suggestions there did help so far.

hjpotter92
  • 78,589
  • 36
  • 144
  • 183
MichaelO
  • 438
  • 1
  • 3
  • 12

4 Answers4

12

Is Apache's CGI module enabled? Try running sudo a2enmod cgi and then restarting Apache.

I had the exact same issue, which ended up being caused by the fact that the CGI module was disabled. In my case, the above command picked and enabled the "cgid" module.

I believe you need the trailing $1 if you're using ScriptAliasMatch, but should omit the $1 (but keep the trailing slash) if you're using ScriptAlias.

You may also need to add a Directory block that looks something like this:

<Directory "/usr/lib/git-core">
    Options +ExecCgi -MultiViews +SymLinksIfOwnerMatch
    AllowOverride none
    Order allow,deny
    Allow from all
    Require all granted
</Directory>
segfault
  • 572
  • 1
  • 7
  • 20
  • You're welcome! I had quite a time trying to set this up yesterday and came across your question while researching it. :) – segfault Nov 06 '14 at 15:42
  • Thanks, I lost hours on this.. with Apache 2.4 I had to change authorization directive to the new syntax: "Require all granted" and enable mod-cgi with "a2enmod cgi". – user570605 Dec 11 '15 at 02:00
  • But in which file must these configurations be appended? apache2.conf or httpd.conf? – nix86 Nov 26 '19 at 08:44
  • @nix86 This is a good answer to your question about which configuration file to use: https://superuser.com/a/676330/64392 – segfault Dec 02 '19 at 06:07
  • I'm migrating a git configuration from an old Debian server to a new one. The old one didn't need this node at all; dropping that into the configuration fixes it. – Kaz Mar 01 '22 at 17:23
1

For other people running into similar problems with this specific error:

fatal: https://server/git/oswald.git/info/refs not valid: is this a git repository?

I eventually found what was causing this issue for me on CentOS 6.5: SELinux. Try running the following command:

setenforce 0

If that fixes your issue, then you have a permissions issue with ACLs. Granted, by running the above command, you've turned off a whole host of permissions checks, but it can at least tell you whether this is what's causing your problem. For more information, check out the documentation here.

Turn the checks back on by running

setenforce 1
Hank Schultz
  • 553
  • 5
  • 11
0

I don't know if you solved it yet, but take a look at my answer here

I have a couple of ideas:

  • In my experience accessing the repository with https failed, while http worked.

  • You don't mention changing the repo directory owner to match the apache user, have you done that?

  • Have you confirmed that the git-http-backend script is located where you expect it to be?

Community
  • 1
  • 1
Marmoy
  • 8,009
  • 7
  • 46
  • 74
  • It didn't work, but with the combined answer from segfault and you, I was able to get it running. Unfortunately, I can only flag one answer as the solution, I would have given both. Thank you! – MichaelO Nov 06 '14 at 10:20
  • Don't worry about it. If you found that something was missing from the answer I directed you to, you could add the missing info. – Marmoy Nov 10 '14 at 13:47
0

Add this:

<Directory /usr/lib/git-core>
  Require all granted
</Directory>