2012-09-08

git + apache + windows xp

日前在 windows xp 上架了 git server,第一種是用 git (for windows ) ,架在 apache 上,第二種是用 gitolite ,架在 cygwin 上,這篇記錄第一種 git server 安裝設定步驟:

1) 至 http://git-scm.com 下載  git for windows (這篇文章使用的是 1.7.11 版)

2) 安裝時都使用預設的選項,此頁選項選擇 Use Git Bash only 。

3) 安裝完成之後到 git 安裝目錄下(C:\Program Files\Git\bin\)將 libiconv-2.dll 檔案複製到(C:\Program Files\Git\libexec\git-core\)

4) 至 http://httpd.apache.org/download.cgi 下載 apache Win32 Binary including OpenSSL 0.9.8t(這篇文章使用的是 2.2.22 版)
5) 至 C:\Program Files\Apache Software Foundation\Apache2.2\conf\ 底下,開啟檔案 httpd.conf 並找到其中:

<Directory />

    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
</Directory>

將 Deny from all 改成 Allow from all,然後插入底下內容:


<Directory "C:/git_repo">

    Options Indexes FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

<Directory "C:/Program Files/Git/libexec/git-core/">

    Options Indexes FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

其中 C:/git_repo 表示未來 git repo 將要置放的路徑。結果如圖:


6) 在檔案最後加入底下內容:


SetEnv GIT_PROJECT_ROOT C:/git_repo

SetEnv GIT_HTTP_EXPORT_ALL
ScriptAliasMatch \
        "(?x)^/git/(.*/(HEAD | \
                        info/refs | \
                        objects/(info/[^/]+ | \
                                 [0-9a-f]{2}/[0-9a-f]{38} | \
                                 pack/pack-[0-9a-f]{40}\.(pack|idx)) | \
                        git-(upload|receive)-pack))$" \
"C:/Program Files/Git/libexec/git-core/git-http-backend.exe/$1"

<Location /git>

AuthType Basic
AuthName "GIT Repository"
AuthUserFile "C:/git_repo/htpasswd"
Require valid-user
</Location>

結果如圖:


7) 建立一個 repo。開啟檔案管理員,在 C:\ 底下建立資料夾 git_repo ,在此資料夾底下按右鍵,選擇 Git Bash。


8) 在 console 模式下輸入 git init --bare test.git,然後進入 test.git 目錄之後再輸入 git update-server-info。


9) 輸入 touch git-daemon-export-ok。


10) 為目錄 git 增加使用者權限:輸入 cd /C/Program\ Files/Apache\ Software\ Foundation/Apache2.2/bin/ 進入該資料夾之後輸入 htpasswd -cmb /C/git_repo/htpasswd git gitpwd 其中 git 為使用者名稱,gitpwd 為密碼。


11) 測試:至根目錄下輸入 git clone http://127.0.0.1/git/test.git,鍵入使用者名稱及密碼之後看到訊息 warning : You appear to have cloned an empty repository 代表 git server 建立完成。



0 意見 :

張貼留言