Web_Interface_using_Gitweb.mdwn 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. On the gitolite side, you enable repositories to be served via the web interface
  2. by doing one of these:
  3. 1. Give read permission to the special user 'gitweb'
  4. 2. Add a gitweb config line to gitolite.conf
  5. The second option allows you to specify a description and an owner for the
  6. repository, so let's use that. For example, let's enable the cool-project
  7. repository to appear on the web interface and give it a description. We just
  8. need to add the following line somewhere in gitolite.conf:
  9. cool-project = "A very cool project"
  10. We can also add an owner:
  11. cool-project "Alice Sandler" = "A very cool project"
  12. gitolite.conf now may look like this:
  13. repo gitolite-admin
  14. RW+ = alice
  15. repo cool-project
  16. RW+ = alice h4ck3r
  17. R = daemon
  18. cool-project = "A very cool project"
  19. Of course the change must be committed and pushed to take effect.
  20. Now, that was just the gitolite side. We still need a webserver to serve the web
  21. pages, and Gitweb itself to generate them from the repository information. So
  22. the steps left are:
  23. 1. Install packages
  24. 2. Configure gitweb
  25. 3. Configure the web server
  26. We'll use lighttpd as the webserver. Alternatively you may prefer Nginx or
  27. Apache or something else. If you do, check their documentation to see how to
  28. configure them. Gitweb comes with a config file for Apache, but I'm not sure it
  29. works (if it does, it definitely saves you the step of configuring the server).
  30. Assume your website name is mysite.org. Later we'll see what to do for I2P. Git
  31. browsing will be available at git.mysite.org.
  32. Let's start by installing packages. Run this as root:
  33. # apt-get install lighttpd gitweb highlight
  34. After this, browsing to your server using a web browser should load the default
  35. page provided by Debian. It will suggest that you replace it. If you already had
  36. a website you won't see that page of course. Anyway, we're going to add the
  37. gitweb interface there.
  38. Now let's configure Gitweb. We need to tell it where to look for the
  39. repositories and give it a list of repositories to serve. By default it just
  40. serves everything it finds, but we will let gitolite.conf control what gitweb
  41. serves by making gitweb use the project list generated by gitolite. Here's what
  42. the config file should look like after installation:
  43. # path to git projects (<project>.git)
  44. $projectroot = "/var/cache/git";
  45. # directory to use for temp files
  46. $git_temp = "/tmp";
  47. # target of the home link on top of all pages
  48. #$home_link = $my_uri || "/";
  49. # html text to include at home page
  50. #$home_text = "indextext.html";
  51. # file with project list; by default, simply scan the projectroot dir.
  52. #$projects_list = $projectroot;
  53. # stylesheet to use
  54. #@stylesheets = ("static/gitweb.css");
  55. # javascript code for gitweb
  56. #$javascript = "static/gitweb.js";
  57. # logo to use
  58. #$logo = "static/git-logo.png";
  59. # the 'favicon'
  60. #$favicon = "static/git-favicon.png";
  61. # git-diff-tree(1) options to use for generated patches
  62. #@diff_opts = ("-M");
  63. @diff_opts = ();
  64. Now, here's our updated file. See `man gitweb.conf` for full documentation of
  65. what can be set in the configuration file.
  66. ################ directories ###############################################
  67. ## path to git projects (<project>.git)
  68. #$projectroot = "/var/cache/git";
  69. $projectroot = "/home/git/repositories";
  70. # directory to use for temp files
  71. $git_temp = "/tmp";
  72. ################ access control ############################################
  73. ## file with project list; by default, simply scan the projectroot dir.
  74. #$projects_list = $projectroot;
  75. ## use the list generated by gitolite
  76. $projects_list = "/home/git/projects.list";
  77. ## a repository will be accessed by gitweb only if it contains this file
  78. ## this is the same file used by git-daemon, to help prevent mistakes
  79. $export_ok = "git-daemon-export-ok";
  80. ## choose whether access control controls what appears in the overview, or
  81. ## also controls what can be accessed at all, i.e. only allow viewing
  82. ## repositories which are also shown in the overview
  83. $strict_export = "true";
  84. ################ links and their targets ###################################
  85. ## stylesheets to use
  86. @stylesheets = ("static/gitweb.css");
  87. ## logo to use
  88. $logo = "static/git-logo.png";
  89. ## the 'favicon'
  90. $favicon = "static/git-favicon.png";
  91. ## target of the home link on top of all pages
  92. #$my_uri = "http://git.mysite.org";
  93. ## label for the home link
  94. $home_link_str = "Projects";
  95. ## where the logo image links
  96. $logo_url = "http://www.mysite.org";
  97. ## label for the logo image
  98. $logo_label = "MySite";
  99. ################ look ######################################################
  100. ## site name to appear in page titles
  101. $site_name = "MySite Git Repositories";
  102. ## name of HTML file to be included at the top of each page
  103. #$site_header =
  104. ## name of HTML file to be included at the bottom of each page
  105. #$site_footer =
  106. ## name of HTML file to be included in the projects overview
  107. #$home_text = "$projectroot/indextext.html";
  108. ## width of the description column in the overview
  109. $projects_list_description_width = 25;
  110. ################ other features and policies ###############################
  111. ## list of base URLs which can be used for cloning repositories
  112. @git_base_url_list = ('git://git.mysite.org',
  113. 'ssh://git@git.mysite.org',
  114. 'http://git.mysite.org');
  115. ## whether to enable categories in the overview
  116. $projects_list_group_categories = "true";
  117. ## disable some potentially CPU-intensive features
  118. $feature{'blame'}{'default'} = [undef];
  119. $feature{'grep'}{'default'} = [undef];
  120. $feature{'pickaxe'}{'default'} = [undef];
  121. $feature{'search'}{'default'} = [undef];
  122. ## enable features
  123. $feature{'highlight'}{'default'} = [1];
  124. ## git-diff-tree(1) options to use for generated patches
  125. #@diff_opts = ("-M");
  126. @diff_opts = ();
  127. Gitweb is now ready to use, but our webserver doesn't know about it yet. We need
  128. to have a link or a path on the website which leads to the Gitweb interface, and
  129. we need to make sure the webserver is able to serve Gitweb's perl module (since
  130. it's not plain static HTML).
  131. Before that, one more thing: The webserver can't read any git content without
  132. read access. We need to add the webserver user to the __git__ group, like we did
  133. for gitdaemon. The default server username is 'www-data' so this command should
  134. give the permissions, run as root:
  135. # adduser www-data git
  136. Time to configure the webserver and we're done. There are many possible
  137. configurations depending on your specific setup and what else your server does,
  138. so we'll do one possible setup: a website at mysite.org and the gitweb interface
  139. at git.mysite.org.
  140. The first thing we'll do is review the initial server setup. This is what Debian
  141. comes with:
  142. server.modules = (
  143. "mod_access",
  144. "mod_alias",
  145. "mod_compress",
  146. "mod_redirect",
  147. # "mod_rewrite",
  148. )
  149. server.document-root = "/var/www"
  150. server.upload-dirs = ( "/var/cache/lighttpd/uploads" )
  151. server.errorlog = "/var/log/lighttpd/error.log"
  152. server.pid-file = "/var/run/lighttpd.pid"
  153. server.username = "www-data"
  154. server.groupname = "www-data"
  155. server.port = 80
  156. index-file.names = ( "index.php", "index.html", "index.lighttpd.html" )
  157. url.access-deny = ( "~", ".inc" )
  158. static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )
  159. compress.cache-dir = "/var/cache/lighttpd/compress/"
  160. compress.filetype = ( "application/javascript", "text/css", "text/html", "text/plain" )
  161. # default listening port for IPv6 falls back to the IPv4 port
  162. include_shell "/usr/share/lighttpd/use-ipv6.pl " + server.port
  163. include_shell "/usr/share/lighttpd/create-mime.assign.pl"
  164. include_shell "/usr/share/lighttpd/include-conf-enabled.pl"
  165. This is much shorter than the sample files provided by lighttpd, but it also has
  166. no comments to explain what's going on. Let's add comments and add the gitweb
  167. host:
  168. ## core modules used by the server
  169. ## mod_access: deny access to files with specific extensions (e.g. backup files)
  170. ## mod_alias: specify special document root for a url subset
  171. ## mod_compress: compress static content to reduce network load
  172. ## mod_redirect: redirect a set of URLs externally
  173. server.modules = (
  174. "mod_access",
  175. "mod_alias",
  176. "mod_compress",
  177. "mod_redirect",
  178. # "mod_rewrite",
  179. )
  180. ## basic setup
  181. server.document-root = "/var/www"
  182. server.upload-dirs = ( "/var/cache/lighttpd/uploads" )
  183. server.errorlog = "/var/log/lighttpd/error.log"
  184. server.pid-file = "/var/run/lighttpd.pid"
  185. server.username = "www-data"
  186. server.groupname = "www-data"
  187. server.port = 80
  188. ## filenames to be used as directory index
  189. index-file.names = ( "index.cgi", "index.html" )
  190. ## deny access to some files by pattern
  191. url.access-deny = ( "~", ".inc" )
  192. ## avoid serving dynamic content generators as static content
  193. static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )
  194. ## directory to use for caching compressed content
  195. compress.cache-dir = "/var/cache/lighttpd/compress/"
  196. ## which file types to compress
  197. compress.filetype = ( "application/javascript", "text/css", "text/html", "text/plain" )
  198. ## default listening port for IPv6 falls back to the IPv4 port
  199. include_shell "/usr/share/lighttpd/use-ipv6.pl " + server.port
  200. ## create mime types
  201. include_shell "/usr/share/lighttpd/create-mime.assign.pl"
  202. ## enable the modules enabled via `lighty-enable-mod` (the conf-enabled folder)
  203. include_shell "/usr/share/lighttpd/include-conf-enabled.pl"
  204. ## gitweb host
  205. $HTTP["host"] == "git.mysite.org" {
  206. server.document-root = "/usr/share/gitweb"
  207. cgi.assign = (
  208. ".cgi" => "/usr/bin/perl"
  209. )
  210. }
  211. Now run this as root to enable CGI:
  212. # lighty-enable-mod cgi
  213. Done.
  214. How to set a local setup: If you have a domain name, you can use it easily. For
  215. example, make sure mysite.org loads the website while git.mysite.org loads the
  216. gitweb interface. If you don't, you'll use localhost or 127.0.0.1 to browse the
  217. local server, but you need to somehow tell the server how to use the gitweb
  218. host. In general, you need a way to pass a "fake" host, and use that host as the
  219. gitweb host in the configuration above. Then localhost will take you to the
  220. website and the fake host will take you to the gitweb interface.
  221. For me, a very simple setup worked: I set the gitweb host to 'localhost', and
  222. then 127.0.0.1 took me to the website while localhost took me to gitweb. I don't
  223. know what happens if you have more virtual hosts on your machine, but for the
  224. configuration described above it's an easy way to test what we did so far.