Difference between revisions of "Gitweb"

From ArchWiki
Jump to: navigation, search
m (typo fixed)
m (No more pacman examples.)
(44 intermediate revisions by 23 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 fitst 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 copy 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
cp -R /usr/share/gitweb/ /srv/http/
+
  
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.
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 23: 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>
  
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:
+
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.
$projectroot = "/path/to/your/repositories";
+
$git_temp = "/tmp";
+
$projects_list = $projectroot;
+
  
Be sure to change the "/path/to/your/repositories" to the path you want your repositories in.
+
=== Lighttpd ===
  
Now the the configuration is done, please restart apache by executing:
+
Add the following to {{ic|/etc/lighttpd/lighttpd.conf}}:
  /etc/rc.d/httpd restart
+
  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" )
 +
}
  
=Adding repositories=
+
You may also need to add {{ic|".css" &#61;> "text/css"}} to the {{ic|mimetype.assign}} line for GitWeb to display properly.
To add a repository go to your repository folder. There make your repository like so:
+
 
 +
=== Nginx ===
 +
 
 +
Consider you've symlinked {{ic|ln -s /usr/share/gitweb /var/www}}, append this location to your nginx configuration:
 +
{{hc|/etc/nginx/nginx.conf|
 +
<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
 +
 
 +
[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</nowiki>
 +
}}
 +
In the end, enable and restart the services:
 +
{{bc|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 {{ic|/etc/gitweb.conf}} and place this in it:
 +
{{hc|/etc/gitweb.conf|<nowiki>
 +
$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>);
 +
</nowiki>}}
 +
 
 +
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 {{Pkg|highlight}} package:
 +
 
 +
When highlight has been installed, simply add this line to your {{ic|gitweb.conf}}:
 +
{{bc|<nowiki>$feature{'highlight'}{'default'} = [1];</nowiki>}}
 +
 
 +
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
 
  mkdir my_repository.git
 
  git init --bare my_repository.git/
 
  git init --bare my_repository.git/
 
  cd my_repository.git/
 
  cd my_repository.git/
 
  touch git-daemon-export-ok
 
  touch git-daemon-export-ok
  echo "Short project's description" > description
+
  echo "Short project's description" > .git/description
  
Next open the "config" file and add this:
+
Next open the {{ic|.git/config}} file and add this:
 
  [gitweb]
 
  [gitweb]
 
         owner = Your Name
 
         owner = Your Name
Line 51: Line 143:
 
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.
 
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 don't 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.
 
+
=Git daemon=
+
This will allow url's like "git clone git://localhost/my_repository.git".
+
Do know that this git:// protocol is read only!
+
Execute this line:
+
git daemon --base-path=/path/to/your/repositories --detach --syslog --export-all
+
 
+
Again be sure to change the "/path/to/your/repositories" to what you used.
+
 
+
To run the command every time at boot, just add the line to your /etc/rc.local.
+
  
Now you can simply use:
+
== See also ==
git clone git://localhost/my_repository.git
+
  
=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 21:23, 29 August 2013

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.

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/gitweb.conf and place this in it:

/etc/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.