「Gitweb」の版間の差分
Kusanaginoturugi (トーク | 投稿記録) (「行った」「一) |
(同期) |
||
| 3行目: | 3行目: | ||
Gitweb は [[git]] 自体に含まれているデフォルトのウェブインターフェイスであり [[cgit]], [[en2:gitosis|gitosis]] といった他の git スクリプトのベースにもなっています。 |
Gitweb は [[git]] 自体に含まれているデフォルトのウェブインターフェイスであり [[cgit]], [[en2:gitosis|gitosis]] といった他の git スクリプトのベースにもなっています。 |
||
| − | + | Gitweb は fcgi をネイティブでサポートしているため、cgi スクリプトとしてラッピングする必要はありません [http://repo.or.cz/w/alt-git.git?a=blob_plain;f=gitweb/INSTALL][https://sixohthree.com/1402/running-gitweb-in-fastcgi-mode]。 |
|
== インストール == |
== インストール == |
||
| − | + | Gitweb をインストールするには、まず {{Pkg|git}} とウェブサーバーをインストールしてください。ここで、テストを行いたい場合は、{{ic|git instaweb}} のヘルプを見て下さい。完全なセットアップをする場合、以下を読んで下さい。 |
|
ここでは {{Pkg|apache}} を例として用いますが {{Pkg|nginx}}, {{Pkg|lighttpd}} などを使うことも可能です。 |
ここでは {{Pkg|apache}} を例として用いますが {{Pkg|nginx}}, {{Pkg|lighttpd}} などを使うことも可能です。 |
||
| 30行目: | 30行目: | ||
SetHandler cgi-script |
SetHandler cgi-script |
||
</Files> |
</Files> |
||
| − | SetEnv GITWEB_CONFIG /etc/ |
+ | SetEnv GITWEB_CONFIG /etc/gitweb/gitweb.conf |
</Directory> |
</Directory> |
||
| 63行目: | 63行目: | ||
PerlResponseHandler ModPerl::Registry |
PerlResponseHandler ModPerl::Registry |
||
PerlOptions +ParseHeaders |
PerlOptions +ParseHeaders |
||
| − | SetEnv GITWEB_CONFIG /etc/ |
+ | SetEnv GITWEB_CONFIG /etc/gitweb/gitweb.conf |
</Directory> |
</Directory> |
||
</IfModule> |
</IfModule> |
||
| 78行目: | 78行目: | ||
以下を {{ic|/etc/lighttpd/lighttpd.conf}} に追加: |
以下を {{ic|/etc/lighttpd/lighttpd.conf}} に追加: |
||
server.modules += ( "mod_alias", "mod_cgi", "mod_redirect", "mod_setenv" ) |
server.modules += ( "mod_alias", "mod_cgi", "mod_redirect", "mod_setenv" ) |
||
| − | setenv.add-environment = ( "GITWEB_CONFIG" => "/etc/ |
+ | setenv.add-environment = ( "GITWEB_CONFIG" => "/etc/gitweb/gitweb.conf" ) |
url.redirect += ( "^/gitweb$" => "/gitweb/" ) |
url.redirect += ( "^/gitweb$" => "/gitweb/" ) |
||
alias.url += ( "/gitweb/" => "/usr/share/gitweb/" ) |
alias.url += ( "/gitweb/" => "/usr/share/gitweb/" ) |
||
| 90行目: | 90行目: | ||
=== Nginx === |
=== Nginx === |
||
| + | Nginx に、この location を追加 (この location を変更するとよいでしょう): |
||
| − | {{ic|# ln -s /usr/share/gitweb /srv/http}} とシンボリックリンクを作成した場合、nginx の設定に以下の location を追加: |
||
{{hc|/etc/nginx/nginx.conf| |
{{hc|/etc/nginx/nginx.conf| |
||
| − | <nowiki>location /gitweb |
+ | <nowiki>location /gitweb.cgi { |
| + | include fastcgi_params; |
||
| − | index gitweb.cgi; |
||
| + | gzip off; |
||
| − | include fastcgi_params; |
||
| + | fastcgi_param SCRIPT_FILENAME /usr/share/gitweb/gitweb.cgi; |
||
| − | gzip off; |
||
| − | + | fastcgi_param GITWEB_CONFIG /etc/gitweb.conf; |
|
| + | fastcgi_pass unix:/var/run/fcgiwrap.sock; |
||
| − | if ($uri ~ "/gitweb/gitweb.cgi") { |
||
| + | } |
||
| − | fastcgi_pass unix:/var/run/fcgiwrap.sock; |
||
| + | |||
| − | } |
||
| + | location / { |
||
| + | root /usr/share/gitweb; |
||
| + | index gitweb.cgi; |
||
}</nowiki> |
}</nowiki> |
||
}} |
}} |
||
| 126行目: | 129行目: | ||
=== Gitweb の設定 === |
=== Gitweb の設定 === |
||
| − | 次に gitweb の設定ファイルを作成する必要があります。{{ic|/etc/ |
+ | 次に gitweb の設定ファイルを作成する必要があります。{{ic|/etc/gitweb/gitweb.conf}} ファイルを開いて (ファイルが存在しない場合は作成して) 以下のように記述してください: |
| − | {{hc|/etc/ |
+ | {{hc|/etc/gitweb/gitweb.conf|<nowiki> |
our $git_temp = "/tmp"; |
our $git_temp = "/tmp"; |
||
| 170行目: | 173行目: | ||
これで gitweb の "Owner" フィールドが入りますが、必須ではありません。 |
これで gitweb の "Owner" フィールドが入りますが、必須ではありません。 |
||
| + | 上記の設定では、このリポジトリをコミットのプッシュ先の"中央"リポジトリストレージとして扱っているので、オーバーヘッドを最小限に抑え、git デーモンを使えるようにするために git-daemon-export-ok と --bare を使っています。 |
||
| − | 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. |
||
上記の設定でリポジトリが作成できます。全て上手く設定できていれば http://localhost/gitweb で確認できます。gitweb の cgi スクリプトがリポジトリのフォルダを読み込むので、リポジトリを追加したときに apache を再起動する必要はありません。 |
上記の設定でリポジトリが作成できます。全て上手く設定できていれば http://localhost/gitweb で確認できます。gitweb の cgi スクリプトがリポジトリのフォルダを読み込むので、リポジトリを追加したときに apache を再起動する必要はありません。 |
||
2016年10月23日 (日) 03:46時点における版
Gitweb は git 自体に含まれているデフォルトのウェブインターフェイスであり cgit, gitosis といった他の git スクリプトのベースにもなっています。
Gitweb は fcgi をネイティブでサポートしているため、cgi スクリプトとしてラッピングする必要はありません [1][2]。
目次
インストール
Gitweb をインストールするには、まず git とウェブサーバーをインストールしてください。ここで、テストを行いたい場合は、git instaweb のヘルプを見て下さい。完全なセットアップをする場合、以下を読んで下さい。
ここでは apache を例として用いますが nginx, lighttpd などを使うことも可能です。
現在の gitweb のデフォルトからウェブサーバーのディレクトリにリンクを作成する必要があります。次の例ではデフォルトのフォルダを使用します:
# ln -s /usr/share/gitweb /srv/http/gitweb
設定
Apache 2.2
以下を /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/gitweb/gitweb.conf </Directory>
バーチャルホストを使っている場合、以下を /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>
また、設定を /etc/httpd/conf/extra/ の設定ファイルに記述することもできますが、そうするかどうかはあなた次第です。
Apache 2.4
Apache 2.4 の場合、git と apache に加えて mod_perlAUR をインストールしてください。
/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/gitweb/gitweb.conf
</Directory>
</IfModule>
以下の行を /etc/httpd/conf/httpd.conf のモジュールセクションに追記:
LoadModule perl_module modules/mod_perl.so
以下の行を /etc/httpd/conf/httpd.conf の最後に追加:
# gitweb configuration Include conf/extra/httpd-gitweb.conf
Lighttpd
以下を /etc/lighttpd/lighttpd.conf に追加:
server.modules += ( "mod_alias", "mod_cgi", "mod_redirect", "mod_setenv" )
setenv.add-environment = ( "GITWEB_CONFIG" => "/etc/gitweb/gitweb.conf" )
url.redirect += ( "^/gitweb$" => "/gitweb/" )
alias.url += ( "/gitweb/" => "/usr/share/gitweb/" )
$HTTP["url"] =~ "^/gitweb/" {
cgi.assign = ( ".cgi" => "" )
server.indexfiles = ( "gitweb.cgi" )
}
また、GitWeb を正しく表示させるには mimetype.assign の行に ".css" => "text/css" を追加する必要があります。
Nginx
Nginx に、この location を追加 (この 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;
}
Nginx#CGI を動かすに従っている場合は include fastcgi_params; を include fastcgi.conf; に置き換えて下さい。
また、fcgiwrap と spawn-fcgi をインストールして fcgiwrap のサービスファイルを編集する必要があります:
/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
最後に、サービスを有効化・再起動:
systemctl enable nginx fcgiwrap systemctl start nginx fcgiwrap
Gitweb の設定
次に gitweb の設定ファイルを作成する必要があります。/etc/gitweb/gitweb.conf ファイルを開いて (ファイルが存在しない場合は作成して) 以下のように記述してください:
/etc/gitweb/gitweb.conf
our $git_temp = "/tmp"; # 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>);
"blame" (ソースファイルの各行の著者を表示) を有効にするには、以下の行を追加:
$feature{'blame'}{'default'} = [1];
設定が完了したら、ウェブサーバーを再起動してください。apache の場合:
systemctl restart httpd
lighttpd の場合:
systemctl restart lighttpd
シンタックスハイライト
Gitweb でシンタックスハイライトを使うには、まず highlight パッケージをインストールしてください。
highlight をインストールしたら、以下の行を gitweb.conf に追加します:
$feature{'highlight'}{'default'} = [1];
ファイルを保存すればハイライトが有効になります。
リポジトリの追加
リポジトリフォルダにリポジトリを追加するには、以下のようにリポジトリを作成:
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
次に config ファイルを開いて以下を追加:
[gitweb]
owner = Your Name
これで gitweb の "Owner" フィールドが入りますが、必須ではありません。
上記の設定では、このリポジトリをコミットのプッシュ先の"中央"リポジトリストレージとして扱っているので、オーバーヘッドを最小限に抑え、git デーモンを使えるようにするために git-daemon-export-ok と --bare を使っています。
上記の設定でリポジトリが作成できます。全て上手く設定できていれば http://localhost/gitweb で確認できます。gitweb の cgi スクリプトがリポジトリのフォルダを読み込むので、リポジトリを追加したときに apache を再起動する必要はありません。
トラブルシューティング
An error occurred while reading CGI reply (no response received)
http://localhost/gitweb をブラウザで開いたときに、このエラーメッセージが表示されることがあります。コマンドラインで gitweb.cgi を実行することで、完全なエラーメッセージを取得することができます (ln -s /usr/share/gitweb /srv/http を実行している場合):
$ perl /srv/http/gitweb/gitweb.cgi
Can't locate CGI.pm in @INC (you may need to install the CGI module) (@INC contains: /usr/lib/perl5/site_perl /usr/share/perl5/site_perl /usr/lib/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib/perl5/core_perl /usr/share/perl5/core_perl .) at gitweb/gitweb.cgi line 13.
この問題を解決するには、perl-cgi をインストールしてください。バグレポートも存在します: FS#45431。
参照
- How To Install A Public Git Repository On A Debian Server — このページは主に HowtoForge を基にしています。