顯示具有 Apache2 標籤的文章。 顯示所有文章
顯示具有 Apache2 標籤的文章。 顯示所有文章

31 1月 2012

Git over Apache2 http server in Ubuntu 11.10

由於手邊的MBP年事已高(五歲多囉),而且RAM最大僅能加到3G,開了IDE與Browser後已經沒什麼多餘的能力來支撐一個VM了。所以把另一台NB裝上Ubuntu 11.10,並將常用的服務裝上去,順便做些更新的筆記。
先前也曾經有個安裝筆記GIT + Apache2 on Ubuntu 8.10 (1),但現在的Ubuntu安裝又更簡單些;主要是因為現在提供了git-http-backend,設定上可以更簡化了。

 

  1. 安裝apache 與 git
    sudo apt-get install apache2 git
    
    後期的Ubuntu 已將git-core更名為git,但是用git-core也沒問題啦。
  2. 建立相關人員帳號密碼,-c代表要建新檔,-m代表密碼要加密
    sudo htpasswd -cm /etc/apache2/passwd $username
    第二位成員起就不需要加-c,只要用-m即可
    sudo htpasswd -m /etc/apache2/passwd $username
  3. 建立git repositories目錄,依習慣,一定要先有repository root。
    sudo mkdir /srv/git
    再建要用的repository,並修改owner為www-data,$reponame代表repository的名稱,.git雖然可加可不加,但建議是要有,.git不會加到clone回來的目錄名稱上
    sudo git --bare init /srv/git/$reponame.git
    sudo chown -R www-data:www-data /srv/git/$reponame.git
  4. 建立dav_git.conf到/etc/apache2/mods-available,並link到/etc/apache2/mods-enabled,檔名可以隨意,但副檔名一定要是conf.
    cd /etc/apache2/mods-available
    sudo vim dav_git.conf

    編輯內容如下

    #若無設定GIT_HTTP_EXPORT_ALL,則在每個repository下必需有git-daemon-export-ok這個檔案才能被外部存取。
    SetEnv GIT_PROJECT_ROOT /srv/git
    SetEnv GIT_HTTP_EXPORT_ALL
    ScriptAlias /git/ /usr/lib/git-core/git-http-backend/
    #用Location的話代表讀寫都要認證,如果希望開放給anonymous讀取,請改用LocationMatch即可
    <Location /git>
            AuthType Basic
            AuthName "Git"
            Require valid-user
            AuthUserFile /etc/apache2/passwd
    </Location>
    
    建立link到/etc/apache2/mods-enabled
    cd /etc/apache2/mods-enabled
    sudo ln -s ../mods-available/dav_git.conf dav_git.conf
  5. 重起apache2即可

 

 

20 11月 2009

Apache2 mod_ssl : SSLPassPhraseDialog

最近都在處理platform的事,好像很久沒coding...

SSL的private key可以用來保護,但在一般server上為了方便,常㑹使用去除Pass Phrase的key,否則每次啟動都要輸入Pass Phrase,對我這種不太重視資安的人是比較麻煩些。

這次遇到的問題是Apache2 SSL module用的private key一定要用Pass Phrase,平時沒在用的功能,只好推說要回去確認,再回家拜請Google大神,不過答案在Apache2的mod_ssl文件中就很淸楚了


改一下mod_ssl.conf,只要把原來

SSLPassPhraseDialog builtin
改成
SSLPassPhraseDialog exec:/ect/apache2/key.sh #位置,檔名隨你高興

key.sh只要這様寫
#!/bin/bash
echo 'your pass phrase'
這様就解決囉

key.sh也不一定要是shell script,也可以用其他languae implement,重點是要把pass phrase寫入stdout。

06 8月 2009

Apache2 + SSL on Ubuntu 8.10

主要是參照SSL on Ubuntu 8.10 Apache2

(1)Open Apache SSL Module
sudo a2enmod ssl
(2)Create server's private key and certificate
cd /etc/apache2
sudo openssl genrsa -des3 -out server.key 1024
sudo openssl req -new -key server.key -out server.csr
sudo openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
這時會問些國家、公司之類的問題,照著回答就OK了,回答的資料會顥示在Browser的憑證清單裡
(3)Install the key and certificate:
sudo cp server.crt /etc/ssl/certs/
sudo cp server.key /etc/ssl/private/
(4)Edit default-ssl configuration
sudo vim /etc/apache2/sites-available/default-ssl
add
SSLEngine on
SSLCertificateFile /etc/ssl/certs/server.crt
SSLCertificateKeyFile /etc/ssl/private/server.key
SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
(5)Enable default-ssl and restart apache2
sudo a2ensite default-ssl
sudo /etc/init.d/apache2 restart

05 8月 2009

GIT + Apache2 on Ubuntu 8.10 (1)

前言
很早前就聽過GIT這個分散式的VCS,但是因為Subversion對我而言實在相當夠用,一直沒有想要更換的念頭,直到最近開始用了JRuby 才有了用用看的念頭,花了點時間確認GIT可以透過Apache走HTTP/HTTPS來checkin/checkout,而且Maven的SCM也支援GIT, 就開始了跟GIT奮戰的過程,我想至少花了4小時才確認這個GIT的Service是可用的。主要是因為不熟GIT的command,無法確認是否正 常。

安裝
(0)由於我已經有安裝了Apache2與Subversion,所以略過Apache2及DAV module的安裝,並且採用Subversion的帳號密碼檔

(1)安裝git-core curl

$>sudo apt-get install git-core curl

這時執行

$>git --version

應該會出現下到訊息,代表git應該可以用了
git version 1.5.6.3

再來是建立curl會用到帳密

$>touch ~/.netrc
然後在.netrc中加入下列資料

machine localhost
login youraccount #same with subversion
password yourpassword #same with subversion

(2)建立GIT repository

$>sudo mkdir /var/lib/git #先建一個git root,再將其他repository放在其下
$>sudo mkdir /var/lib/git/repo1
$>cd /var/lib/git/repo1
$>sudo git --bare init
$>sudo git-update-server-info
$>sudo chmod +x hooks/post-update #在透過http commit後會自動執行git-update-server-info
你會看到下列這樣的訊息,代表init成功
Initialized empty Git repository in /var/lib/git/repo1/
再設定權限,讓Apache2可以存取
$>sudo chown www-data:www-data -R /var/lib/git

(3)enable apache2 dav_fs, dav module
$>sudo a2enmod dav_fs
$>sudo a2enmod dav
因為我已經有裝Subversion,想說應該不用設定才是,後來發現只有起用dav這個module,而dav_fs沒起用,就是不行
所以還是記得要確認一下

(4)config git dav
建立Apache2用的GIT DAV設定
$>sudo touch /etc/apache2/mods-available/dav_git.conf
$>sudo ln -s /etc/apache2/mods-available/dav_git.conf /etc/apache2/mods-enabled/dav_git.conf
然後修改/etc/apache2/mods-available/dav_git.conf,將在第2個Step中加入的GIT Repository設為DAV,並指定
HTTP連結路徑為/git/repo1

Alias /git "/var/lib/git"
<Location /git/repo1>
	DAV on
	AuthType Basic
	AuthName "Git Repository"
	AuthUserFile "/etc/apache2/dav_svn.passwd"
	Require valid-user
</Location>

(5)restart apache2

$>sudo /etc/init.d/apache2 restart
這時再用Browser連結http://localhost:8080/git/repo1/HEAD,輸入帳密後應該可以看見下列訊息
ref: refs/heads/master

(6)clone repo1
在任一空目錄下執行git clone

$>git clone http://localhost/git/repo1
應該可以看到
Initialized empty Git repository in /yourpath/repo1/.git/
warning: You appear to have cloned an empty repository.

(7)test commit

$>touch readme
$>git add readme
$>git commit -m "first"
[master (root-commit) 29db40b] first
0 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 readme
$>git push origin master
Fetching remote heads...
refs/
refs/heads/
refs/tags/
updating 'refs/heads/master'
from 0000000000000000000000000000000000000000
to 29db40b949a69400ea4377c28703b6073c91d785
sending 3 objects
done
Updating remote server info