Difference between revisions of "Gitweb"

From ArchWiki
Jump to: navigation, search
m (a link to git was missing (except for merge notes))
(37 intermediate revisions by 21 users not shown)
Line 1: Line 1:
Gitweb is the default web interface provided with [[git]] itself and is the basis for other git scripts like cgit, gitosis and others.
+
[[Category:Version Control System]]
=Installation=
+
Gitweb is the default web interface provided with [[git]] itself and is the basis for other git scripts like [[cgit]], [[gitosis]] and others.
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:
+
gitweb actually supports fcgi natively, so you don't 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
ln -s /usr/share/gitweb /srv/http/gitweb
+
  
That's it for the "installation". Next is the configuration.
+
== Installation ==
  
=Configuration=
+
To install gitweb you first have to install {{Pkg|git}} and a webserver. For this example we use {{Pkg|apache}} but you can also use {{Pkg|nginx}}, {{Pkg|lighttpd}} or others.
==Apache==
+
 
Add the following to the end of you /etc/httpd/conf/httpd.conf
+
Next you need to link the current gitweb default to your webserver location. In this example I use the default folder locations:
 +
# 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.}}
 +
 
 +
== Configuration ==
 +
 
 +
=== Apache ===
 +
 
 +
Add the following to the end of your {{ic|/etc/httpd/conf/httpd.conf}}
 
  <Directory "/srv/http/gitweb">
 
  <Directory "/srv/http/gitweb">
 
     DirectoryIndex gitweb.cgi
 
     DirectoryIndex gitweb.cgi
Line 24: Line 30:
 
  </Directory>
 
  </Directory>
  
You can put the configuration in it's own config file in /etc/httpd/conf/extra/ but that's up to you to decide.
+
If using a virtualhosts configuration, add this to {{ic|/etc/httpd/conf/extra/httpd-vhosts.conf}}
 +
<VirtualHost *:80>
 +
    ServerName gitserver
 +
    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>
  
==Lighttpd==
+
You could also put the configuration in it's own config file in {{ic|/etc/httpd/conf/extra/}} but that's up to you to decide.
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:
+
 
 +
==== Apache 2.4 ====
 +
 
 +
For Apache 2.4 you need to install {{Pkg|mod_perl}} along with {{Pkg|git}} and {{Pkg|apache}}.
 +
 
 +
Create {{ic|/etc/httpd/conf/extra/httpd-gitweb.conf}}
 +
<IfModule mod_perl.c>
 +
    Alias /gitweb "/usr/share/gitweb"
 +
    <Directory "/usr/share/gitweb">
 +
        DirectoryIndex gitweb.cgi
 +
        Require all granted
 +
        Options ExecCGI
 +
        AddHandler perl-script .cgi
 +
        PerlResponseHandler ModPerl::Registry
 +
        PerlOptions +ParseHeaders
 +
        SetEnv  GITWEB_CONFIG  /etc/conf.d/gitweb
 +
    </Directory>
 +
</IfModule>
 +
 
 +
Add the following line to the modules section of {{ic|/etc/httpd/conf/httpd.conf}}
 +
LoadModule perl_module modules/mod_perl.so
 +
 
 +
Add the following line to the end of {{ic|/etc/httpd/conf/httpd.conf}}
 +
# gitweb configuration
 +
Include conf/extra/httpd-gitweb.conf
 +
 
 +
=== Lighttpd ===
 +
 
 +
Add the following to {{ic|/etc/lighttpd/lighttpd.conf}}:
 +
server.modules += ( "mod_alias", "mod_cgi", "mod_redirect", "mod_setenv" )
 
  setenv.add-environment = ( "GITWEB_CONFIG" => "/etc/conf.d/gitweb.conf" )
 
  setenv.add-environment = ( "GITWEB_CONFIG" => "/etc/conf.d/gitweb.conf" )
 
  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" => "")
+
         cgi.assign = ( ".cgi" => "" )
         server.indexfiles = ("gitweb.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 not existing) the file /etc/conf.d/gitweb.conf and place this in it:
+
$projectroot = "/path/to/your/repositories";
+
$git_temp = "/tmp";
+
$projects_list = $projectroot;
+
our @git_base_url_list = qw(git://<your_server> git@<your_server>:~);
+
  
{{Note|Replace "/path/to/your/repositories" with your path and replace "<your_server>" with your servername or ip (localhost for example). As for the ":~" part in the "git@<your_server>:~" line. It now expects the git repos to bei n your home folder! Also change that accordingly.}}
+
=== Nginx ===
  
Now the the configuration is done, please restart your webserver.
+
Consider you've symlinked {{ic|ln -s /usr/share/gitweb /var/www}}, append this location to your nginx configuration:
For apache:
+
{{hc|/etc/nginx/nginx.conf|
  /etc/rc.d/httpd restart
+
<nowiki>location /gitweb/ {
 +
        index gitweb.cgi;
 +
        include fastcgi_params;
 +
        gzip off;
 +
        fastcgi_param  GITWEB_CONFIG /etc/conf.d/gitweb.conf;
 +
        if ($uri ~ "/gitweb/gitweb.cgi") {
 +
                fastcgi_pass    unix:/var/run/fcgiwrap.sock;
 +
        }
 +
}</nowiki>
 +
}}
 +
Additionally, we have to install {{Pkg|fcgiwrap}} and {{Pkg|spawn-fcgi}} and modify the fcgiwrap service file:
 +
{{hc|/usr/lib/systemd/system/fcgiwrap.service|
 +
<nowiki>[Unit]
 +
Description=Simple server for running CGI applications over FastCGI
 +
After=syslog.target network.target
  
Or for lighttpd:
+
[Service]
/etc/rc.d/lighttpd restart
+
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
  
=Adding repositories=
+
[Install]
To add a repository go to your repository folder. There make your repository like so:
+
WantedBy=multi-user.target</nowiki>
mkdir my_repository.git
+
}}
git init --bare my_repository.git/
+
In the end, enable and restart the services:
cd my_repository.git/
+
{{bc|systemctl enable nginx fcgiwrap
touch git-daemon-export-ok
+
systemctl start nginx fcgiwrap}}
echo "Short project's description" > description
+
  
Next open the "config" file and add this:
+
=== Gitweb config ===
[gitweb]
+
        owner = Your Name
+
  
This will fill in the "Owner" field in gitweb. It's not required.
+
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>
 +
$git_temp = "/tmp";
  
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.
+
# The directories where your projects are. Must not end with a slash.
 +
$projectroot = "/path/to/your/repositories";
  
That is all for making a repository. You can now see it on your http://localhost/gitweb (assuming everything went fine). You don't need to restart apache for new repositories since the gitweb cgi script simply reads your repository folder.
+
# Base URLs for links displayed in the web interface.
 +
our @git_base_url_list = qw(git://<your_server> http://git@<your_server>);
 +
</nowiki>}}
  
=Git daemon=
+
To enable "blame" view (showing the author of each line in a source file), add the following line:
{{Merge|Git}}
+
$feature{'blame'}{'default'} = [1];
{{Note|Merge note. This section should belong in [[Git]] and this article should link to that page.}}
+
{{Note|The git daemon only allows read access. For write access look at "Git SSH".}}
+
This will allow url's like "git clone git://localhost/my_repository.git".
+
  
Edit configuration file for git-dameon /etc/conf.d/git-daemon.conf (GIT_REPO is a place with your git projects), then start git-daemon with root privileges:
+
Now the the configuration is done, please restart your webserver.
  /etc/rc.d/git-daemon start
+
For apache:
 +
  systemctl restart httpd
  
To run the git-daemon every time at boot, just append git-deamon to DAEMONS line in /etc/rc.conf file.
+
Or for lighttpd:
 +
systemctl restart lighttpd
  
Clients can now simply use:
+
=== Syntax highlighting ===
git clone git://localhost/my_repository.git
+
  
=Git SSH=
+
To enable syntax highlighting with Gitweb, you have to first install the {{Pkg|highlight}} package:
{{Merge|Git}}
+
{{Note|Merge note. This section should belong in [[Git]] and this article should link to that page.}}
+
You first need to have a public SSH key. For that follow the guide at [[Using SSH Keys]]. To setup SSH itself you need to follow the [[SSH]] guide. I assume you have a public SSH key now and your SSH is working.
+
Open your SSH key in your favorite editor (default public key name is id_rsa.pub and is located in ~/.ssh) and copy it's content (CTRL + C).
+
Now go to your user where you have made your git repository, since we now need to allow that SSH key to login on that user to access the GIT repository.
+
Open this file in your favorite editor (i use nano)
+
nano ~/.ssh/authorized_keys
+
and paste the contents of id_rsa.pub in it. Be sure it is all on one line! That is important! It should look somewhat like this:
+
{{Warning|Do not copy the line below! It is an example! It will not work if you use that line!}}
+
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQCboOH6AotCh4OcwJgsB4AtXzDo9Gzhl+BAHuEvnDRHNSYIURqGN4CrP+b5Bx/iLrRFOBv58TcZz1jyJ2PaGwT74kvVOe9JCCdgw4nSMBV44cy+6cTJiv6f1tw8pHRS2H6nHC9SCSAWkMX4rpiSQ0wkhjug+GtBWOXDaotIzrFwLw== username@hostname
+
Now you can checkout your git repo this way (change where needed. Here it's using the git username and localhost):
+
git clone git@localhost:my_repository.git
+
You should now get an SSH yes/no question. Type yes followed by enter. Then you should have your repository checked out. Since this is with SSH you also do have commit rights now. For that look at [[Git]] and [[Super Quick Git Guide]].
+
  
=Git HTTP=
+
When highlight has been installed, simply add this line to your {{ic|gitweb.conf}}:
{{Merge|Git}}
+
{{bc|<nowiki>$feature{'highlight'}{'default'} = [1];</nowiki>}}
{{Note|Merge note. This section should belong in [[Git]] and this article should link to that page.}}
+
This section will explain how to do a git clone over http. For now this is only reading (cloning), not writing (pushing).
+
First you need to make your Git repositories accessable over your web server. So lets assume your git repositories are outside of the default apache documentroot. You can skip this part if they are within your apache documentroot.
+
  
==Read access==
+
Save the file and highlighting should now be enabled.
Lets assume your git repositories are in /usr/git. You need to add an Alias to apache and a Directory section to make it accessable.
+
Append the following to your /etc/httpd/conf/httpd/conf (change where your paths differ. the /git-repos is how it will be accessible in your browser like : http://localhost/git-repos):
+
Alias /git-repos /usr/git
+
<Directory "/usr/git">
+
    Options Indexes FollowSymLinks MultiViews ExecCGI
+
    AllowOverride All
+
    Order allow,deny
+
    Allow from all
+
</Directory>
+
  
Save it and restart apache:
+
== Adding repositories ==
/etc/rc.d/httpd restart
+
  
Now you should see your git repositories at http://localhost/git-repos or whatever you choose as "git-repos" name in the above alias name.
+
To add a repository go to your repository folder, make your repository like so:
Next we need to do a "git update-server-info" in your local git repository. Note that you must do that where the actual git repo is created, not where you cloned it. So run this in your git repository:
+
mkdir my_repository.git
  git update-server-info
+
git init --bare my_repository.git/
 +
cd my_repository.git/
 +
  touch git-daemon-export-ok
 +
echo "Short project's description" > .git/description
  
That command is needed to be able to clone over http so it's better to make a post-update hook for it so this command always runs when you do a push to the repository. To get that done go to your git repository in the "hooks" folder and run this:
+
Next open the {{ic|.git/config}} file and add this:
  mv post-update.sample post-update
+
  [gitweb]
 +
        owner = Your Name
  
We can do this because the default post-update.sample hook is doing exactly what we want (running git update-server-info after a commit).
+
This will fill in the "Owner" field in gitweb. It's not required.
  
Last we need to make a change to gitweb.conf to show the url for http cloning. Open gitweb.conf in your favorite editor (i use nano):
+
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.
nano /etc/conf.d/gitweb.conf
+
  
Find the line (the dots resamble some content in that line:
+
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.
our @git_base_url_list = qw(...)
+
Add something like this (again depends on what you did with the Alias in Apache):
+
our @git_base_url_list = qw(... http://localhost/git-repos)
+
That will result in clone lines like so:
+
git clone http://localhost/git-repos/your_repository.git
+
  
==Write access==
+
== See also ==
{{Note|Someone has to fill this one in. It's with DAV..?}}
+
Possible sources for this part:
+
http://kaeso.wordpress.com/2008/02/02/git-repository-with-apache-via-webdav-and-gitweb/
+
http://www.kernel.org/pub/software/scm/git/docs/howto/setup-git-server-over-http.txt
+
  
=Thanx to...=
+
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.
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.
+

Revision as of 15:06, 15 March 2014

Gitweb is the default web interface provided with git itself and is the basis for other git scripts like cgit, gitosis and others.

gitweb actually supports fcgi natively, so you don't 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

Installation

To install gitweb you first have to install git and a webserver. For this example we use apache but you can also use nginx, lighttpd or others.

Next you need to link the current gitweb default to your webserver location. In this example I use the default folder locations:

# ln -s /usr/share/gitweb /srv/http/gitweb
Note: You may want to double check the server directory to make sure the symbolic links were made.

Configuration

Apache

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

<Directory "/srv/http/gitweb">
   DirectoryIndex gitweb.cgi
   Allow from all
   AllowOverride all
   Order allow,deny
   Options ExecCGI
   <Files gitweb.cgi>
   SetHandler cgi-script
   </Files>
   SetEnv  GITWEB_CONFIG  /etc/conf.d/gitweb.conf
</Directory>

If using a virtualhosts configuration, add this to /etc/httpd/conf/extra/httpd-vhosts.conf

<VirtualHost *:80>
    ServerName gitserver
    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.

Apache 2.4

For Apache 2.4 you need to install mod_perl along with git and apache.

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

<IfModule mod_perl.c>
    Alias /gitweb "/usr/share/gitweb"
    <Directory "/usr/share/gitweb">
        DirectoryIndex gitweb.cgi
        Require all granted
        Options ExecCGI
        AddHandler perl-script .cgi
        PerlResponseHandler ModPerl::Registry
        PerlOptions +ParseHeaders
        SetEnv  GITWEB_CONFIG  /etc/conf.d/gitweb
    </Directory>
</IfModule>

Add the following line to the modules section of /etc/httpd/conf/httpd.conf

LoadModule perl_module modules/mod_perl.so

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

# gitweb configuration
Include conf/extra/httpd-gitweb.conf

Lighttpd

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

server.modules += ( "mod_alias", "mod_cgi", "mod_redirect", "mod_setenv" )
setenv.add-environment = ( "GITWEB_CONFIG" => "/etc/conf.d/gitweb.conf" )
url.redirect += ( "^/gitweb$" => "/gitweb/" )
alias.url += ( "/gitweb/" => "/usr/share/gitweb/" )
$HTTP["url"] =~ "^/gitweb/" {
       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

Consider you've symlinked ln -s /usr/share/gitweb /var/www, append this location to your nginx configuration:

/etc/nginx/nginx.conf
location /gitweb/ {
        index gitweb.cgi;
        include fastcgi_params;
        gzip off;
        fastcgi_param   GITWEB_CONFIG  /etc/conf.d/gitweb.conf;
        if ($uri ~ "/gitweb/gitweb.cgi") {
                fastcgi_pass    unix:/var/run/fcgiwrap.sock;
        }
}

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

/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, enable and restart the services:

systemctl enable nginx fcgiwrap
systemctl start nginx fcgiwrap

Gitweb config

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

/etc/conf.d/gitweb.conf
$git_temp = "/tmp";

# The directories where your projects are. Must not end with a slash.
$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, please restart your webserver. For apache:

systemctl restart httpd 

Or for lighttpd:

systemctl restart lighttpd

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" > .git/description

Next open the .git/config file and add this:

[gitweb]
        owner = Your Name

This will fill in the "Owner" field in gitweb. It's 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.

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

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.