Ubuntu下通过gitweb来浏览源码

本文介绍了如何在Ubuntu系统中快速搭建一个Git服务器,通过GitWeb来浏览源码,包括安装Git和OpenSSH,创建Git用户,安装Apache2和GitWeb,配置GitWeb并建立试例仓库。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  看到kernel官网上的gitweb(https://git.kernel.org/),有没有自己弄一个的冲动。


本文介绍在ubuntu下快速搭建一个git服务器,通过gitweb来浏览源码。


安装git和openssh:

sudo apt-get install git-core openssh-server openssh-client

建立git用户

建立git用户,home目录为/home/git,该目录专门来放git仓库   

sudo adduser --system --shell /bin/sh  --gecos 'git version control' --group --disabled-password --home /home/git git

sudo passwd git

安装apache2


sudo apt-get install apache2

安装gitweb

sudo apt-get install gitweb


修改gitweb配置

vi /etc/gitweb.conf可看到

$projectroot = "/var/lib/git";

由于我们采用/home/git作为gitweb的工作目录,这里将工作目录改为

$projectroot = "/home/git";

重启apache2

sudo /etc/init.d/apache2 restart
访问gitweb
http://localhost/gitweb/

工作路径默认是没有源码的,这时要建一个git裸仓,然后将源码推送到裸仓上。

1切换到git用户,并进入工作目录su git,cd /home/git

2建立裸仓git init --bare driver.git

3找一个git仓库,添加远程地址,如git remote add origin git@192.168.199.157:/home/git/driver.git

4推送源码到裸仓中,git push origin master:master

5网页访问localhost/gitweb就可看到driver.git


对应Ubuntu14.04,可参考文章http://blog.youkuaiyun.com/caspiansea/article/details/41952139


对于Ubuntu16.04还需进行小范围的修改,

查看/etc/apache2/conf-available/gitweb.conf文件,可知

<IfModule mod_alias.c>
  <IfModule mod_mime.c>
    <IfModule mod_cgi.c>
      Define ENABLE_GITWEB
    </IfModule>
    <IfModule mod_cgid.c>
      Define ENABLE_GITWEB
    </IfModule>
  </IfModule>
</IfModule>

<IfDefine ENABLE_GITWEB>
  Alias /gitweb /usr/share/gitweb

  <Directory /usr/share/gitweb>
    Options +FollowSymLinks +ExecCGI
    AddHandler cgi-script .cgi
  </Directory>
</IfDefine>

要声明了enable_gitweb,才能用gitweb,由上述代码可知,要加载了特定的模块才能使用该宏,默认只加载了下列的模块,那加载一下需要的模块即可。查看apachectl的模块(http://blog.youkuaiyun.com/qmhball/article/details/7631384)

w@w-Lenovo-G470:~$ apachectl -t -D DUMP_MODULES 
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
Loaded Modules:
 core_module (static)
 so_module (static)
 watchdog_module (static)
 http_module (static)
 log_config_module (static)
 logio_module (static)
 version_module (static)
 unixd_module (static)
 access_compat_module (shared)
 alias_module (shared)
 auth_basic_module (shared)
 authn_core_module (shared)
 authn_file_module (shared)
 authz_core_module (shared)
 authz_host_module (shared)
 authz_user_module (shared)
 autoindex_module (shared)
 cgid_module (shared)
 deflate_module (shared)
 dir_module (shared)
 env_module (shared)
 filter_module (shared)
 mime_module (shared)
 mpm_event_module (shared)
 negotiation_module (shared)
 setenvif_module (shared)
 status_module (shared)

cd /etc/apache2/mods-enabled

root@w-Lenovo-G470:/etc/apache2/mods-enabled# a2enmod alias mime cgid
Module alias already enabled
Module mime already enabled
Module cgid already enabled

重启apache2服务

sudo /etc/init.d/apache2 restart

如果ubuntu是服务器版本(/var/log/apache2/error.log报错aborted at /usr/share/gitweb/index.cgi line 13),需安装桌面环境

 sudo apt-get install ubuntu-desktop

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值