Project

General

Profile

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

Revision 1 (trevcan, 2022-05-08 19:36) → Revision 2/17 (trevcan, 2022-05-09 15:36)

h1. How to set up a git server over HTTP (s) 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 h3. *+This is a guide on how to set up a git over HTTP(s) server. 
 The git protocol used for this will be _Smart HTTP_, refer to the Refs section. server.+* 

 h2. 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  
 <pre><code class="shell"> 
 chmod and chown 
 </code></pre> 
 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  
 <pre><code class="shell">www-data</code></pre> 
 user and group for lighttpd. This is fine, as long as you change all your git repos and chown/chmod them. 

 h2. Step 2: Dependencies You can use these commands to change ownership and Modules. file modes of files. 

 For system dependencies, you will require (of course) <pre><code class="shell"> 
 - @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: # assumes root 
 - @mod_auth@ cd /var/www/git/ 
 - @mod_cgi@ chown --recursive git:www-data *.git 
 - @mod_alias@ chmod --recursive u=rwx,g=rwx *.git 
 - @mod_auth@ 
 - @mod_setenv@ </code></pre> 

 h3. Step 3: Bare Minimum Config. 

 *You must use This will make it a subdomain or another domain altogether* , else shared repo between the CGI script will get confused `git` 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 `www-data` user. It will allow read-only access recursively modify all files under folders ending with ".git" in order to let 
 the repositories under that directory. group read, write, and execute. 

 <pre><code> 

 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 = ( "" => "" ) 
	 } 

 } 

 </code></pre> 


 h2. References 

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