Project

General

Profile

Actions

How to set up a git server over http(s) » History » Revision 2

« Previous | Revision 2/17 (diff) | Next »
trevcan, 2022-05-09 15:36


How to set up a git server over HTTP (s)

One may have already set up a git server, it's as easy as enabling ssh on a *NIX machine.

But one may have encountered the not-so-usual situation where you're on a random network
and you can't access port 22!.

This is a guide on how to set up a git over HTTP server.
The git protocol used for this will be Smart HTTP, refer to the Refs section.

Step 1: Permissions, permissions and more permissions!

See: https://redmine.lighttpd.net/projects/lighttpd/wiki/FrequentlyAskedQuestions#Why-do-I-get-403-Forbidden

Permissions are very important ! Remember that git will be performing reads and writes to directories and files ! Be sure to set up your user and group correctly. You may have to

chmod and chown

your git repo in order for it to be accessible to your user. You cannot change user/group at runtime of lighttpd.

In most cases, users will have the

www-data

user and group for lighttpd. This is fine, as long as you change all your git repos and chown/chmod them.

Step 2: Dependencies and Modules.

For system dependencies, you will require (of course)
- git (make sure you have the /usr/lib/git-core/git-http-backend binary, this should be installed by default with the git package on Arch Linux)

For lighttpd modules, you will require:
- mod_auth
- mod_cgi
- mod_alias
- mod_auth
- mod_setenv

Step 3: Bare Minimum Config.

You must use a subdomain or another domain altogether , else the CGI script will get confused and won't
be able to read the paths correctly.

The bare minimum to get the CGI git-http-backend script working is to set
the environment variable GIT_PROJECT_ROOT to the parent directory of one of your git repositories.

This will allow read-only access to the repositories under that directory.



server.modules += ("mod_setenv", "mod_cgi", "mod_alias")

$HTTP["host"] == "git-test.thetrevor.tech" {

    $HTTP["scheme"]    == "https" {

        auth.backend.plain.userfile = "/var/log/lighttpd-plain.user"  

        alias.url = ( "" => "/usr/lib/git-core/git-http-backend" )

        setenv.set-environment = ( "GIT_PROJECT_ROOT" => "/var/www/git/" )
        setenv.set-environment += ( "GIT_HTTP_EXPORT_ALL" => "" )

        cgi.assign = ( "" => "" )
    }

}

References

- Smart HTTP git docs: https://git-scm.com/book/en/v2/Git-on-the-Server-Smart-HTTP

Updated by trevcan almost 2 years ago · 2 revisions