Ubuntu下通过gitweb来浏览源码

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

Ubuntu下通过gitweb来浏览源码_第1张图片

本文介绍在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/

Ubuntu下通过gitweb来浏览源码_第2张图片

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

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

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

3找一个git仓库,添加远程地址,如git remote add origin [email protected]:/home/git/driver.git

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

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


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


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

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


  
    
      Define ENABLE_GITWEB
    
    
      Define ENABLE_GITWEB
    
  



  Alias /gitweb /usr/share/gitweb

  
    Options +FollowSymLinks +ExecCGI
    AddHandler cgi-script .cgi
  

要声明了enable_gitweb,才能用gitweb,由上述代码可知,要加载了特定的模块才能使用该宏,默认只加载了下列的模块,那加载一下需要的模块即可。查看apachectl的模块(http://blog.csdn.net/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

你可能感兴趣的:(TOOLS)