201203200200[Git] Archlinux 架設 Git server 與 Gitweb
Git 是目前廣泛使用的版本控制工具,安裝 Git 的 repositories server 步驟也滿容易的
一、安裝 Git
sudo pacman -S git
二、建立與初始化 repository
1) 建立 git 帳號
sudo useradd -m git
2) 讓其他 user 有權限可以讀取 git 家目錄 (為了讓 gitweb 有權訪問 repsoitories)
sudo chmod 755 /home/git
3) 登入使用者 git,開始建立 repository
mkdir <專案名稱>.git # ex: mkdir my_repository.git cd <專案名稱>.git # ex: cd my_repository.git git --bare init
4) 接著在任何機器上(有git功能,並且具有專案原始碼),使用以下指令初始化專案
cd <專案名稱> # ex: cd my_repository git init git add . # 加入所有專案目錄下的檔案 git commit -m "initial project" git remote add origin git@<server ip>:<專案名稱>.git git push origin master
接著就可以在任何裝有 git 並經過授權的機器上取得專案原始碼
git clone git@<server ip>:<專案名稱>.git
三、安裝 apache 與設定 gitweb
為了讓使用者瞭解 repositories 的狀況,提供 repositories 的網頁瀏覽介面給使用者看是一個不錯的方式,在 archlinux 中預設安裝 git 時也會安裝 gitweb,因此我們只需要安裝 apache 即可
1) 安裝 apache
sudo pacman -S apache
2) 安裝 syntax highlighting 套件
sudo pacman -S highlight
3) 將 gitweb (預設是 /usr/share/gitweb ) link 到 apache 目錄下 (預設是 /srv/http )
sudo ln -s /usr/share/gitweb /srv/http/gitweb
4) 打開 apache 設定檔 (/etc/httpd/conf/httpd.conf) 並在最後面加入
<Directory "/srv/http/gitweb"> DirectoryIndex gitweb.cgi Allow from all AllowOverride none Order allow,deny Options ExecCGI <Files gitweb.cgi> SetHandler cgi-script </Files> SetEnv GITWEB_CONFIG /etc/conf.d/gitweb.conf </Directory>
5) 在 /etc/conf.d/gitweb.conf 新增或修改檔案
$git_temp = "/tmp"; # The directories where your repositories are $projectroot = "/home/git/"; # Set the displayed length of description $projects_list_description_width = 50; # Enable blame view $feature{'blame'}{'default'} = [1]; # Enable syntax highlighting wit gitweb $feature{'highlight'}{'default'} = [1];
6) 重新啟動 apache
sudo /etc/rc.d/httpd restart
完成後利用瀏覽器開啟網址 http://<server ip>/gitweb/ 就可以看到結果了
四、gitweb 登入要求
另外如果要登入才可訪問 gitweb 的話可以利用 apache 所提供的 htpasswd 功能
1) 產生帳密檔
cd /srv/http/gitweb htpasswd -cb .htpasswd <帳號> <密碼> # -c 為 建立檔案,若檔案已存在則 -b 即可
2) 將 apache 中 DAV 的功能打開
編輯剛剛的 apache 設定檔 (/etc/httpd/conf/httpd.conf) 改為
<Directory "/srv/http/gitweb"> DAV on AuthType Basic AuthName "Private Git Repository" AuthUserFile /srv/http/gitweb/.htpasswd Require valid-user DirectoryIndex gitweb.cgi Allow from all AllowOverride none Order allow,deny Options ExecCGI <Files gitweb.cgi> SetHandler cgi-script </Files> SetEnv GITWEB_CONFIG /etc/conf.d/gitweb.conf </Directory>
3) 重新啟動 apache
sudo /etc/rc.d/httpd restart
如此就必須輸入帳號及密碼,才能訪問 gitweb 頁面
Reference
Archlinux wiki
https://wiki.archlinux.org/index.php/Gitweb
ArchLinux 下安裝 git, gitosis, gitweb 服務
http://blog.yxwang.me/2009/05/install-git-gitoss-gitweb-in-archlinux/
Debian Linux 架設 Gitweb
http://blog.longwin.com.tw/2009/05/debian-linux-build-gitweb-2009/
在 gitweb 網站上加入簡單的 htpasswd 帳號管理
http://wildjcrt.pixnet.net/blog/post/27930651-在-gitweb-網站上加入簡單的-htpasswd-帳號管理
在 linode 上架設私人 Git 伺服器
http://dongbeta.com/post/1361
by autosun