Difference between revisions of "Gitweb"

From ArchWiki
Jump to: navigation, search
(Gitweb config)
(See also: HTTPS)
 
(50 intermediate revisions by 28 users not shown)
Line 1: Line 1:
 
[[Category:Version Control System]]
 
[[Category:Version Control System]]
Gitweb is the default web interface provided with [[git]] itself and is the basis for other git scripts like [[cgit]], [[gitosis]] and others.
+
[[ja:Gitweb]]
 +
Gitweb is the default web interface that comes with [[Git]] and is the basis for other Git scripts like [[cgit]] and [[gitosis]].
  
==Installation==
+
Gitweb actually supports FCGI natively, so you do not need to wrap it as a CGI script. [http://repo.or.cz/w/alt-git.git?a=blob_plain;f=gitweb/INSTALL][https://sixohthree.com/1402/running-gitweb-in-fastcgi-mode]
To install gitweb you first have to install git and a webserver. For this example we use apache but you can also use others:
 
pacman -S git apache
 
  
Next you need to link the current gitweb default to your webserver location. In this example I use the default folder locations:
+
== Installation ==
ln -s /usr/share/gitweb /srv/http/gitweb
 
  
{{Note|1=You may want to double check the server directory to make sure the symbolic links were made.}}
+
To install gitweb you first have to install {{Pkg|git}} and a webserver. Now, if you want to quickly test it, see the help of {{ic|git instaweb}}. Otherwise, if you want a comprehensive setup, keep reading.
  
That's it for the "installation". Next is the configuration.
+
For this example we use {{Pkg|apache}} but you can also use {{Pkg|nginx}}, {{Pkg|lighttpd}} or others.
  
==Configuration==
+
For all the examples below, you need to [[install]] the {{Pkg|perl-cgi}} package. ({{bug|45431}})
===Apache===
+
 
Add the following to the end of your /etc/httpd/conf/httpd.conf
+
== Configuration ==
<Directory "/srv/http/gitweb">
+
 
 +
=== Apache ===
 +
 
 +
Create {{ic|/etc/httpd/conf/extra/gitweb.conf}}
 +
{{hc|gitweb.conf|
 +
Alias /gitweb "/usr/share/gitweb"
 +
<Directory "/usr/share/gitweb">
 
     DirectoryIndex gitweb.cgi
 
     DirectoryIndex gitweb.cgi
    Allow from all
 
    AllowOverride all
 
    Order allow,deny
 
 
     Options ExecCGI
 
     Options ExecCGI
 +
    Require all granted
 
     <Files gitweb.cgi>
 
     <Files gitweb.cgi>
 
     SetHandler cgi-script
 
     SetHandler cgi-script
 
     </Files>
 
     </Files>
     SetEnv  GITWEB_CONFIG  /etc/conf.d/gitweb.conf
+
     SetEnv  GITWEB_CONFIG  /etc/gitweb.conf
</Directory>
+
</Directory>
 +
}}
  
If using a virtualhosts configuration, add this to /etc/httpd/conf/extra/httpd-vhosts.conf
+
Add the following line to the end of {{ic|/etc/httpd/conf/httpd.conf}}
  <VirtualHost *:80>
+
  # gitweb configuration
    ServerName gitserver
+
Include conf/extra/gitweb.conf
    DocumentRoot /var/www/gitweb
 
    <Directory /var/www/gitweb>
 
        Options ExecCGI +FollowSymLinks +SymLinksIfOwnerMatch
 
        AllowOverride All
 
        order allow,deny
 
        Allow from all
 
        AddHandler cgi-script cgi
 
        DirectoryIndex gitweb.cgi
 
    </Directory
 
</VirtualHost>
 
  
You could also put the configuration in it's own config file in /etc/httpd/conf/extra/ but that's up to you to decide.
+
If Apache refuses to display gitweb, but prints the plain source code of the perl script instead, it is very likely that {{ic|cgi_module}} has not been loaded by Apache.  
  
===Lighttpd===
+
In order to resolve this issue, add the following line to {{ic|/etc/httpd/conf/httpd.conf}}
If you're using lighttpd, make sure mod_alias, mod_redirect, mod_cgi and mod_setenv are loaded. Add the following to /etc/lighttpd/lighttpd.conf:
+
LoadModule cgi_module modules/mod_cgi.so
  server.modules += ( "mod_setenv" )
+
 
setenv.add-environment = ( "GITWEB_CONFIG" => "/etc/conf.d/gitweb.conf" )
+
=== Lighttpd ===
 +
 
 +
Add the following to {{ic|/etc/lighttpd/lighttpd.conf}}:
 +
  server.modules += ( "mod_alias", "mod_cgi", "mod_redirect", "mod_setenv" )
 
  url.redirect += ( "^/gitweb$" => "/gitweb/" )
 
  url.redirect += ( "^/gitweb$" => "/gitweb/" )
 
  alias.url += ( "/gitweb/" => "/usr/share/gitweb/" )
 
  alias.url += ( "/gitweb/" => "/usr/share/gitweb/" )
 
  $HTTP["url"] =~ "^/gitweb/" {
 
  $HTTP["url"] =~ "^/gitweb/" {
         cgi.assign = (".cgi" => "")
+
        setenv.add-environment = (
         server.indexfiles = ("gitweb.cgi")
+
                "GITWEB_CONFIG" => "/etc/gitweb.conf",
 +
                "PATH" => env.PATH
 +
        )
 +
         cgi.assign = ( ".cgi" => "" )
 +
         server.indexfiles = ( "gitweb.cgi" )
 
  }
 
  }
  
===Gitweb config===
+
You may also need to add {{ic|".css" &#61;> "text/css"}} to the {{ic|mimetype.assign}} line for GitWeb to display properly.
Next we need to make a gitweb config file. Open (or create if it does not exist) the file {{ic|/etc/conf.d/gitweb.conf}} and place this in it:
+
 
{{hc|/etc/conf.d/gitweb.conf|<nowiki>
+
=== Nginx ===
$git_temp = "/tmp";
+
 
 +
Append this location to your nginx configuration (you might want to change the location):
 +
{{hc|/etc/nginx/nginx.conf|
 +
location /gitweb.cgi {
 +
    include fastcgi_params;
 +
    gzip off;
 +
    fastcgi_param  SCRIPT_FILENAME  /usr/share/gitweb/gitweb.cgi;
 +
    fastcgi_param  GITWEB_CONFIG  /etc/gitweb.conf;
 +
    fastcgi_pass    unix:/var/run/fcgiwrap.sock;
 +
}
 +
 
 +
location / {
 +
    root /usr/share/gitweb;
 +
    index gitweb.cgi;
 +
}
 +
}}
 +
If you follow [[Nginx#CGI implementation]], try replacing {{ic|include fastcgi_params;}} with {{ic|include fastcgi.conf;}}.
 +
 
 +
Additionally, we have to install {{Pkg|fcgiwrap}} and {{Pkg|spawn-fcgi}} and modify the fcgiwrap service file:
 +
 
 +
{{Accuracy|Files in {{ic|/usr/lib/}} should not be modified, see [[systemd#Editing provided units]].}}
  
 +
{{hc|/usr/lib/systemd/system/fcgiwrap.service|2=
 +
[Unit]
 +
Description=Simple server for running CGI applications over FastCGI
 +
After=syslog.target network.target
 +
 +
[Service]
 +
Type=forking
 +
Restart=on-abort
 +
PIDFile=/var/run/fcgiwrap.pid
 +
ExecStart=/usr/bin/spawn-fcgi -s /var/run/fcgiwrap.sock -P /var/run/fcgiwrap.pid -u http -g http -- /usr/sbin/fcgiwrap
 +
ExecStop=/usr/bin/kill -15 $MAINPID
 +
 +
[Install]
 +
WantedBy=multi-user.target
 +
}}
 +
In the end, [[start/enable]] {{ic|fcgiwrap.service}}.
 +
 +
=== Gitweb config ===
 +
 +
Next we need to make a gitweb config file. Open (or create if it does not exist) the file {{ic|/etc/gitweb.conf}} and place this in it:
 +
{{hc|/etc/gitweb.conf|2=
 
# The directories where your projects are. Must not end with a slash.
 
# The directories where your projects are. Must not end with a slash.
$projectroot = "/path/to/your/repositories";  
+
our $projectroot = "/path/to/your/repositories";  
  
 
# Base URLs for links displayed in the web interface.
 
# Base URLs for links displayed in the web interface.
 
our @git_base_url_list = qw(git://<your_server> http://git@<your_server>);  
 
our @git_base_url_list = qw(git://<your_server> http://git@<your_server>);  
</nowiki>}}
+
}}
  
 
To enable "blame" view (showing the author of each line in a source file), add the following line:
 
To enable "blame" view (showing the author of each line in a source file), add the following line:
 
  $feature{'blame'}{'default'} = [1];
 
  $feature{'blame'}{'default'} = [1];
  
Now the the configuration is done, please restart your webserver.
+
Now the the configuration is done, restart your webserver.
For apache:
 
systemctl restart httpd
 
  
 +
=== Syntax highlighting ===
  
Or for lighttpd:
+
To enable syntax highlighting with Gitweb, you have to first install the {{Pkg|highlight}} package:
systemctl restart lighttpd
 
 
 
===Syntax highlighting===
 
 
 
To enable syntax highlighting with Gitweb, you have to first install the {{Pkg|highlight}} package from <nowiki>[community]</nowiki>:
 
pacman -S highlight
 
  
 
When highlight has been installed, simply add this line to your {{ic|gitweb.conf}}:
 
When highlight has been installed, simply add this line to your {{ic|gitweb.conf}}:
{{bc|<nowiki>$feature{'highlight'}{'default'} = [1];</nowiki>}}
+
$feature{'highlight'}{'default'} = [1];
  
 
Save the file and highlighting should now be enabled.
 
Save the file and highlighting should now be enabled.
  
==Adding repositories==
+
== Adding repositories ==
 +
 
 
To add a repository go to your repository folder, make your repository like so:
 
To add a repository go to your repository folder, make your repository like so:
 
  mkdir my_repository.git
 
  mkdir my_repository.git
Line 96: Line 131:
 
  echo "Short project's description" > description
 
  echo "Short project's description" > description
  
Next open the "config" file and add this:
+
Next open the {{ic|config}} file and add this:
 
  [gitweb]
 
  [gitweb]
        owner = Your Name
+
owner = Your Name
  
This will fill in the "Owner" field in gitweb. It's not required.
+
This will fill in the "Owner" field in gitweb. It is not required.
  
I assumed that you want to have this repository as "central" repository storage where you push your commits to so the git-daemon-export-ok and --bare are here to have minimal overhead and to allow the git daemon to be used on it.
+
This assumes that you want to have this repository as "central" repository storage where you push your commits to so the git-daemon-export-ok and --bare are here to have minimal overhead and to allow the git daemon to be used on it.
  
 
That is all for making a repository. You can now see it on your http://localhost/gitweb (assuming everything went fine). You do not need to restart apache for new repositories since the gitweb cgi script simply reads your repository folder.
 
That is all for making a repository. You can now see it on your http://localhost/gitweb (assuming everything went fine). You do not need to restart apache for new repositories since the gitweb cgi script simply reads your repository folder.
  
==Thanks to...==
+
== See also ==
This howto was mainly based on the awesome howto from howtoforge: http://www.howtoforge.com/how-to-install-a-public-git-repository-on-a-debian-server I only picked the parts that are needed to get it working and left the additional things out.
+
 
 +
* [https://www.howtoforge.com/how-to-install-a-public-git-repository-on-a-debian-server How To Install A Public Git Repository On A Debian Server] — HowtoForge page used as the main source for this article.

Latest revision as of 17:46, 9 November 2017

Gitweb is the default web interface that comes with Git and is the basis for other Git scripts like cgit and gitosis.

Gitweb actually supports FCGI natively, so you do not need to wrap it as a CGI script. [1][2]

Installation

To install gitweb you first have to install git and a webserver. Now, if you want to quickly test it, see the help of git instaweb. Otherwise, if you want a comprehensive setup, keep reading.

For this example we use apache but you can also use nginx, lighttpd or others.

For all the examples below, you need to install the perl-cgi package. (FS#45431)

Configuration

Apache

Create /etc/httpd/conf/extra/gitweb.conf

gitweb.conf
Alias /gitweb "/usr/share/gitweb"
<Directory "/usr/share/gitweb">
    DirectoryIndex gitweb.cgi
    Options ExecCGI
    Require all granted
    <Files gitweb.cgi>
    SetHandler cgi-script
    </Files>
    SetEnv  GITWEB_CONFIG  /etc/gitweb.conf
</Directory>

Add the following line to the end of /etc/httpd/conf/httpd.conf

# gitweb configuration
Include conf/extra/gitweb.conf

If Apache refuses to display gitweb, but prints the plain source code of the perl script instead, it is very likely that cgi_module has not been loaded by Apache.

In order to resolve this issue, add the following line to /etc/httpd/conf/httpd.conf

LoadModule cgi_module modules/mod_cgi.so

Lighttpd

Add the following to /etc/lighttpd/lighttpd.conf:

server.modules += ( "mod_alias", "mod_cgi", "mod_redirect", "mod_setenv" )
url.redirect += ( "^/gitweb$" => "/gitweb/" )
alias.url += ( "/gitweb/" => "/usr/share/gitweb/" )
$HTTP["url"] =~ "^/gitweb/" {
       setenv.add-environment = (
               "GITWEB_CONFIG" => "/etc/gitweb.conf",
               "PATH" => env.PATH
       )
       cgi.assign = ( ".cgi" => "" )
       server.indexfiles = ( "gitweb.cgi" )
}

You may also need to add ".css" => "text/css" to the mimetype.assign line for GitWeb to display properly.

Nginx

Append this location to your nginx configuration (you might want to change the location):

/etc/nginx/nginx.conf
location /gitweb.cgi {
    include fastcgi_params;
    gzip off;
    fastcgi_param   SCRIPT_FILENAME  /usr/share/gitweb/gitweb.cgi;
    fastcgi_param   GITWEB_CONFIG  /etc/gitweb.conf;
    fastcgi_pass    unix:/var/run/fcgiwrap.sock;
}

location / {
    root /usr/share/gitweb;
    index gitweb.cgi;
}

If you follow Nginx#CGI implementation, try replacing include fastcgi_params; with include fastcgi.conf;.

Additionally, we have to install fcgiwrap and spawn-fcgi and modify the fcgiwrap service file:

Tango-inaccurate.pngThe factual accuracy of this article or section is disputed.Tango-inaccurate.png

Reason: Files in /usr/lib/ should not be modified, see systemd#Editing provided units. (Discuss in Talk:Gitweb#)
/usr/lib/systemd/system/fcgiwrap.service
[Unit]
Description=Simple server for running CGI applications over FastCGI
After=syslog.target network.target

[Service]
Type=forking
Restart=on-abort
PIDFile=/var/run/fcgiwrap.pid
ExecStart=/usr/bin/spawn-fcgi -s /var/run/fcgiwrap.sock -P /var/run/fcgiwrap.pid -u http -g http -- /usr/sbin/fcgiwrap
ExecStop=/usr/bin/kill -15 $MAINPID

[Install]
WantedBy=multi-user.target

In the end, start/enable fcgiwrap.service.

Gitweb config

Next we need to make a gitweb config file. Open (or create if it does not exist) the file /etc/gitweb.conf and place this in it:

/etc/gitweb.conf
# The directories where your projects are. Must not end with a slash.
our $projectroot = "/path/to/your/repositories"; 

# Base URLs for links displayed in the web interface.
our @git_base_url_list = qw(git://<your_server> http://git@<your_server>);

To enable "blame" view (showing the author of each line in a source file), add the following line:

$feature{'blame'}{'default'} = [1];

Now the the configuration is done, restart your webserver.

Syntax highlighting

To enable syntax highlighting with Gitweb, you have to first install the highlight package:

When highlight has been installed, simply add this line to your gitweb.conf:

$feature{'highlight'}{'default'} = [1];

Save the file and highlighting should now be enabled.

Adding repositories

To add a repository go to your repository folder, make your repository like so:

mkdir my_repository.git
git init --bare my_repository.git/
cd my_repository.git/
touch git-daemon-export-ok
echo "Short project's description" > description

Next open the config file and add this:

[gitweb]
owner = Your Name

This will fill in the "Owner" field in gitweb. It is not required.

This assumes that you want to have this repository as "central" repository storage where you push your commits to so the git-daemon-export-ok and --bare are here to have minimal overhead and to allow the git daemon to be used on it.

That is all for making a repository. You can now see it on your http://localhost/gitweb (assuming everything went fine). You do not need to restart apache for new repositories since the gitweb cgi script simply reads your repository folder.

See also