2013年12月16日 星期一

[SA] Hw4 FAMP(FreeBSD+Apache+MySQL+PHP)










  • # 先從 devel/git 的 ports 中安裝 git
  • # 同時間選取 gitweb 以提供網頁界面
  • # 之後遇到的設定頁照原來的 OK OK 就可以
  • cd /usr/ports/devel/git
  • make install clean
  •  
  • # 增加 git 的使用者,並指定 git 的家用目錄為 /home/git
  • # 同時間使用 git-shell 作為 shell 指令, uid, gid 為 9418
  • pw groupadd -n git -g 9418
  • pw useradd -n git -u 9418 -g git -c git -d /home/git -s /usr/local/libexec/git-core/git-shell -h -
  •  
  • # 新增 repo (倉庫 work),並更改屬性
  • chown git:git /home/git
  • chmod 755 /home/git
  •  
  • mkdir /home/git/work/
  • chmod 775 /home/git/work/
  • chown git:git /home/git/work/
  •  
  • # 設定除了 commit 外還可以使用額外指令的用戶
  • # 如果使用者只需要 commit,就可以不加進來
  • vi /etc/group
  • git:*:9418:zeuxis,neo
  •  
  • # 設定 SSH 認證金鑰,因為 git 要用到這東西
  • # 每個使用者的 SSH Key 也要加進 authorized_keys.
  • # 每個 key 為一行
  • mkdir /home/git/.ssh/
  • chmod 700 /home/git/.ssh/
  •  
  • touch /home/git/.ssh/authorized_keys
  • chmod 600 /home/git/.ssh/authorized_keys
  • chown -R git:git /home/git/.ssh/
  •  
  • # 生成指定用戶的 SSH Key
  • # 在安裝情況下是使用 ssh-keygen -d 生成 dsa
  • # 另還可用 ssh-keygen -t rsa 生成 rsa
  • # 生成時 Enter passphrase 無視按下 enter 即可
  • su username
  • ssh-keygen -d
  • su root
  • cat /home/username/.ssh/id_dsa.pub > /home/git/.ssh/anthorized_keys
  •  
  • # 接著設定 git 的 repo
  • mkdir /home/git/work/test.git
  • cd /home/git/work/test.git && git init --bare --shared
  •  
  • # 接著進行一個簡單的測試
  • mkdir /tmp/test && cd /tmp/test && git init
  • echo "This is a test" > index.html
  • git add
  • git commit -m 'added index.html'
  •  
  • # 之後 commit 到遠端的 repo
  • git remote add origin username@example.com:work/test.git
  • git push origin master
  •  
  • # 之後再設定 gitweb
  • mkdir /home/git/public_html
  • chmod 755 /home/git/public_html
  • chown git:git /home/git/public_html
  • cp /usr/local/share/examples/git/gitweb/git* /home/git/public_html
  •  
  • # 再設定 apache
  • <VirtualHost *:80>
  •   ServerAdmin no-reply@example.com
  •   DocumentRoot "/home/git/public_html"
  •   ServerName git.example.com
  •  
  •   <Directory "/home/git/public_html">
  •     Options ExecCGI
  •     Order allow,deny
  •     Allow from all
  •  
  •     DirectoryIndex gitweb.cgi
  •     AddHandler cgi-script .cgi
  •   </Directory>
  • </VirtualHost>
  •  
  • # 之後再編輯 gitweb.cgi
  • our $projectroot = "/home/git/work";
  • our $home_link_str = "work";
  • our $site_name = "git.example.com"
  • our $projects_list_description_width = 40; # 調整 description 空間
  •  
  • # 修改 test.git 的描述
  • echo "test.git" > /home/git/work/test.git/description
  •  
  • # 修改 test.git 的 owner
  • vim /home/git/work/test.git/config
  •  
  • # 在其後面加入
  • [gitweb]
  • owner = zeuxis
  • url = git://git.example.com/work/test.git
  • url = username@git.example.com:work/test.git
  •  
  • # 最後就是設定 Git protocol
  • # 在 /etc/rc.conf 最後加入這段
  • git_daemon_enable="YES"
  • git_daemon_directory="/home/git"
  • git_daemon_flags="--syslog --base-path=/git --export-all"
  •  
  • # 之後啟動 Git Daemon
  • /usr/local/etc/rc.d/git_daemon start
  •  
  • # 如果以上面這句子會出現停在 starting 的字眼可以改為以下句式
  • # 送出後接兩下 Enter 結束即可
  • /usr/local/etc/rc.d/git_daemon start &
  •  
  • # 檢查是否在執行
  • ps -eaf | grep -v grep | grep git
  •  
  • # 如有東西就可以再測試可否使用了
  • cd /tmp/test
  • rm -Rf *
  • git clone git://git.example.com/work/test.git
  • - See more at: http://www.chair.im/?p=597#sthash.2F0agDtP.qSAdRJ2D.dpuf

    Requirement

    • To do this homework , you need 2 domain name.
      • http://twbbs.org/
      • http://www.nctucs.net/
    • You need two hostnames use same IP address.
    • When access http://yourdomain1, it will show the php information.
    • When access http://yourdomain1/sademo.html, it will show the text “This page is for sa demo.”. 
      • Notice that user can use both http and https portocal to access this page.
    • When access http://yourdomain1/private/, user need enter id "nctucs" and password "sahw4" which is implemented by .htaccess. And it will show the text “It’s my secret.”
    • System user sysadm can put file at ~/WWW/ and others can access it by visiting http://yourdomain1/~sysadm/. sysadm's password is your student id.
    • Your git website url is http://yourdomain2/gitweb
    • For demo, you need to put a git repository named “sademo.git”. And it’s decription is “This repository is for sa demo.”.
    • On your website, enter the sademo.git will show URL information, it’s URL is http://yourdomain2/gitweb/sademo.git.
    • You can clone and push your repository by http://yourdomain2/gitweb/sademo.git and password is your student id.
    • Users use cookie authentication when access your phpMyAdmin site http://yourdomain1/phpMyAdmin/
      • (You need to add a MySQL user for authentication).
      • Create another user with limited privilege
      • And notice that if others access http://yourdomain2/phpMyAdmin/, they can not access it.
      • Only 140.113.*.* can access it
      • But 140.113.235.* can’t access it
    • Redirect http://yourdomain1/ILoveSA to http://help.cs.nctu.edu.tw/ 
      • But http://yourdomain2/ILoveSA will not redirect .




    Note

    系統:FreeBSD 9.2

    裝的 ports:
      
    /usr/ports/www/apache22
    /usr/ports/devel/git - for gitweb (要記得選 gitweb)
    /usr/ports/databases/phpmyadmin
    /usr/ports/databases/mysql55-server/
    /usr/ports/lang/php5
    /usr/ports/databases/php5-mysql - MySQL Database
    /usr/ports/www/php5-session - Sessions
    /usr/ports/graphics/php5-gd - Graphics Library



    • When access http://yourdomain1, it will show the php information.
    查了一下才知道,這裡的意思是要在 apache 上跑 php 的 code:

    <?php phpinfo() ?>

    把這行放在 index.php 裏面

    之後再修改 httpd.conf: 
    修改讀的順序,這樣就會先讀 index.php 沒有的話再找 index.html:

    <IfModule dir_module>                                                          
        DirectoryIndex index.php index.html index.htm                              
    </IfModule>


    把這兩行加在最底下:
    AddType application/x-httpd-php .php                                              
    AddType application/x-httpd-php-source .phps



    Reference:

    phpinfo:
    http://php.about.com/od/learnphp/p/PHP_info.htm
    Apache with php:
    http://www.freebsd.org/doc/handbook/network-apache.html
    http://www.freebsdmadeeasy.com/tutorials/web-server/install-php-5-for-web-hosting.php 

    • When access http://yourdomain1/sademo.html, it will show the text “This page is for sa demo.”. 
      • Notice that user can use both http and https portocal to access this page.
    apache 的主要設定檔放在: /usr/local/etc/apache22/httpd.conf
    設定檔中的

    DocumentRoot "/usr/local/www/apache22/data"

    所有的 html 檔都放在這底下(預設會跑到 index.html),所以要這裡只要在底下多放一份 sademo.html 並在裡面加入所需要的資料,就可以完成 http 的部份
    至於 https 就要製作憑證了
    根據下面網址的教學就可以成功製作完憑證並且成功以 https 的方式連線。

    然後在每次啟動 Apache 時可以先以

    service apache22 configtest

    來測試 config 檔案是否正確,之後再啟動 Apache

    Reference:
    Basic concept:
    http://linux.vbird.org/linux_server/0360apache.php#www_basic_bas
    https:
    http://bojack.pixnet.net/blog/post/29718009-%E3%80%90freebsd%E3%80%91apache-%2B-ssl-%E6%86%91%E8%AD%89%E8%A3%BD%E4%BD%9C

    • When access http://yourdomain1/private/, user need enter id "nctucs" and password "sahw4" which is implemented by .htaccess. And it will show the text “It’s my secret.”
    產生密碼檔案的方法:
    htpasswd passwdfile username

    htpasswd -c .htpassed nctucs


    Reference:
    .htaccess: 
    http://backtrue.pixnet.net/blog/post/25172187-%5B%E5%AD%B8%E7%BF%92%5D-apache%E7%9B%AE%E9%8C%84%E4%BF%9D%E8%AD%B7-.htaccess-%E7%9A%84%E5%88%B6%E4%BD%9C 

    • System user sysadm can put file at ~/WWW/ and others can access it by visiting http://yourdomain1/~sysadm/. sysadm's password is your student id.
    visiting http://yourdomain 1/~sysadm/ redirect to ~sysadm/WWW 先將 httpd.conf 裏面的 #Include conf/extra/httpd-userdir.conf 註解拿掉,然後修改 httpd-userdir.conf 裏面,把原本的 public_html 改成 WWW 即可

    在 apache22/data 下面建一個 WWW 的資料夾,裏面的 .htaccess 改成 require user sysadm ,這樣就只有 sysadm 可以進去上傳檔案,然後上傳檔案的 php 寫法在下面聯結有。


    Reference:
    https://httpd.apache.org/docs/2.2/howto/public_html.html
    http://linux.vbird.org/linux_server/0360apache.php#php_upload
    php upload file:
    http://www.w3school.com.cn/php/php_file_upload.asp 
    .htaccess:
    http://backtrue.pixnet.net/blog/post/25172187-%5B%E5%AD%B8%E7%BF%92%5D-apache%E7%9B%AE%E9%8C%84%E4%BF%9D%E8%AD%B7-.htaccess-%E7%9A%84%E5%88%B6%E4%BD%9C

    • Your git website url is http://yourdomain2/gitweb
    • For demo, you need to put a git repository named “sademo.git”. And it’s decription is “This repository is for sa demo.”.
      • On your website, enter the sademo.git will show URL information, it’s URL is http://yourdomain2/gitweb/sademo.git.

      domain2 就要用到 virtual host
      把在 httpd.conf 裏面 Include etc/apache22/extra/httpd-vhosts.conf  註解拿掉,然後修改 httpd-vhosts.conf 的內容即可

      接下來是 git web
      裝好了 git 之後,先增加 git 的使用者,並指定 git 的家用目錄為 /home/git ,同時間使用 git-shell 作為 shell 指令, uid, gid 為 9418

      pw groupadd -n git -g 9418

      pw useradd -n git -u 9418 -g git -c git -d /home/git -s /usr/local/libexec/git-core/git-shell -h -

      新增 repo (倉庫 gitweb),並更改屬性

      chown git:git /home/git

      chmod 755 /home/git

      mkdir /home/git/gitweb/
       

      chmod 775 /home/git/gitweb/
       

      chown git:git /home/git/gitweb/

      接著設定 git 的 repo

      mkdir /home/git/gitweb/sademo.git
      cd /home/git/gitweb/sademo.git
      git init --bare --shared
      接著進行一個簡單的測試

      mkdir /tmp/test && cd /tmp/test && git init
      echo "This is a test" > index.html
      git add index.html
      git commit -m 'added index.html'

      之後 commit 到遠端的 repo

      git remote add origin git@example.com:work/test.git
      git push origin master


      之後再設定 gitweb,因為要求的網址緣故,所以我把東西放到 /usr/local/www/apache22/data/gitweb 資料夾底下

      mkdir /usr/local/www/apache22/data/gitweb
      chmod 755 /usr/local/www/apache22/data/gitweb
      chown git:git /usr/local/www/apache22/data/gitweb
      cp /usr/local/share/examples/git/gitweb/git /usr/local/www/apache22/data/gitweb/.


      再設定 apache

        <Directory "/usr/local/www/apache22/data/gitweb">
          Options +Indexes +ExecCGI +FollowSymLinks
          Order allow,deny
          Allow from all

          DirectoryIndex gitweb.cgi
          AddHandler cgi-script .cgi
        </Directory>




      之後再編輯 gitweb.cgi

      our $projectroot = "/home/git/gitweb";
      our $home_link_str = "gitweb";
      our $site_name = "git.example.com"
      our $projects_list_description_width = 40; # 調整 description 空間
       


      修改 sademo.git 的描述

      echo "This is for sa demo." > /home/git/gitweb/sademo.git/description

      修改 test.git 的 owner

      vim /home/git/gitweb/sademo.git/config

      # 在其後面加入

      [gitweb]
      owner = Wrold Wide Web Owner
      url = http://
      yourdomain2/gitweb/sademo.git. 
      最後就是設定 Git protocol,在 /etc/rc.conf 最後加入這段

      git_daemon_enable="YES"
      git_daemon_directory="/home/git"

      git_daemon_flags="--syslog --base-path=/home/git --export-all --detach"
      之後啟動 Git Daemon

      service git_daemon start

      如有東西就可以再測試可否使用了

      cd /tmp/test
      rm -Rf *
      git clone git://git.example.com/gitwebb/sademo.git



      Reference:
      gitweb:
      https://forums.freebsd.org/viewtopic.php?&t=10810
      http://www.chair.im/?p=597#sthash.2F0agDtP.dpbs 
      clone with apache:
      http://www.jedi.be/blog/2009/05/06/8-ways-to-share-your-git-repository/#apachehttp










    • # 先從 devel/git 的 ports 中安裝 git
    • # 同時間選取 gitweb 以提供網頁界面
    • # 之後遇到的設定頁照原來的 OK OK 就可以
    • cd /usr/ports/devel/git
    • make install clean
    •  
    • # 增加 git 的使用者,並指定 git 的家用目錄為 /home/git
    • # 同時間使用 git-shell 作為 shell 指令, uid, gid 為 9418
    • pw groupadd -n git -g 9418
    • pw useradd -n git -u 9418 -g git -c git -d /home/git -s /usr/local/libexec/git-core/git-shell -h -
    •  
    • # 新增 repo (倉庫 work),並更改屬性
    • chown git:git /home/git
    • chmod 755 /home/git
    •  
    • mkdir /home/git/work/
    • chmod 775 /home/git/work/
    • chown git:git /home/git/work/
    •  
    • # 設定除了 commit 外還可以使用額外指令的用戶
    • # 如果使用者只需要 commit,就可以不加進來
    • vi /etc/group
    • git:*:9418:zeuxis,neo
    •  
    • # 設定 SSH 認證金鑰,因為 git 要用到這東西
    • # 每個使用者的 SSH Key 也要加進 authorized_keys.
    • # 每個 key 為一行
    • mkdir /home/git/.ssh/
    • chmod 700 /home/git/.ssh/
    •  
    • touch /home/git/.ssh/authorized_keys
    • chmod 600 /home/git/.ssh/authorized_keys
    • chown -R git:git /home/git/.ssh/
    •  
    • # 生成指定用戶的 SSH Key
    • # 在安裝情況下是使用 ssh-keygen -d 生成 dsa
    • # 另還可用 ssh-keygen -t rsa 生成 rsa
    • # 生成時 Enter passphrase 無視按下 enter 即可
    • su username
    • ssh-keygen -d
    • su root
    • cat /home/username/.ssh/id_dsa.pub > /home/git/.ssh/anthorized_keys
    •  
    • # 接著設定 git 的 repo
    • mkdir /home/git/work/test.git
    • cd /home/git/work/test.git && git init --bare --shared
    •  
    • # 接著進行一個簡單的測試
    • mkdir /tmp/test && cd /tmp/test && git init
    • echo "This is a test" > index.html
    • git add
    • git commit -m 'added index.html'
    •  
    • # 之後 commit 到遠端的 repo
    • git remote add origin username@example.com:work/test.git
    • git push origin master
    •  
    • # 之後再設定 gitweb
    • mkdir /home/git/public_html
    • chmod 755 /home/git/public_html
    • chown git:git /home/git/public_html
    • cp /usr/local/share/examples/git/gitweb/git* /home/git/public_html
    •  
    • # 再設定 apache
    • <VirtualHost *:80>
    •   ServerAdmin no-reply@example.com
    •   DocumentRoot "/home/git/public_html"
    •   ServerName git.example.com
    •  
    •   <Directory "/home/git/public_html">
    •     Options ExecCGI
    •     Order allow,deny
    •     Allow from all
    •  
    •     DirectoryIndex gitweb.cgi
    •     AddHandler cgi-script .cgi
    •   </Directory>
    • </VirtualHost>
    •  
    • # 之後再編輯 gitweb.cgi
    • our $projectroot = "/home/git/work";
    • our $home_link_str = "work";
    • our $site_name = "git.example.com"
    • our $projects_list_description_width = 40; # 調整 description 空間
    •  
    • # 修改 test.git 的描述
    • echo "test.git" > /home/git/work/test.git/description
    •  
    • # 修改 test.git 的 owner
    • vim /home/git/work/test.git/config
    •  
    • # 在其後面加入
    • [gitweb]
    • owner = zeuxis
    • url = git://git.example.com/work/test.git
    • url = username@git.example.com:work/test.git
    •  
    • # 最後就是設定 Git protocol
    • # 在 /etc/rc.conf 最後加入這段
    • git_daemon_enable="YES"
    • git_daemon_directory="/home/git"
    • git_daemon_flags="--syslog --base-path=/git --export-all"
    •  
    • # 之後啟動 Git Daemon
    • /usr/local/etc/rc.d/git_daemon start
    •  
    • # 如果以上面這句子會出現停在 starting 的字眼可以改為以下句式
    • # 送出後接兩下 Enter 結束即可
    • /usr/local/etc/rc.d/git_daemon start &
    •  
    • # 檢查是否在執行
    • ps -eaf | grep -v grep | grep git
    •  
    • # 如有東西就可以再測試可否使用了
    • cd /tmp/test
    • rm -Rf *
    • git clone git://git.example.com/work/test.git
    • - See more at: http://www.chair.im/?p=597#sthash.2F0agDtP.qSAdRJ2D.dpuf








    • # 先從 devel/git 的 ports 中安裝 git
    • # 同時間選取 gitweb 以提供網頁界面
    • # 之後遇到的設定頁照原來的 OK OK 就可以
    • cd /usr/ports/devel/git
    • make install clean
    •  
    • # 增加 git 的使用者,並指定 git 的家用目錄為 /home/git
    • # 同時間使用 git-shell 作為 shell 指令, uid, gid 為 9418
    • pw groupadd -n git -g 9418
    • pw useradd -n git -u 9418 -g git -c git -d /home/git -s /usr/local/libexec/git-core/git-shell -h -
    •  
    • # 新增 repo (倉庫 work),並更改屬性
    • chown git:git /home/git
    • chmod 755 /home/git
    •  
    • mkdir /home/git/work/
    • chmod 775 /home/git/work/
    • chown git:git /home/git/work/
    •  
    • # 設定除了 commit 外還可以使用額外指令的用戶
    • # 如果使用者只需要 commit,就可以不加進來
    • vi /etc/group
    • git:*:9418:zeuxis,neo
    •  
    • # 設定 SSH 認證金鑰,因為 git 要用到這東西
    • # 每個使用者的 SSH Key 也要加進 authorized_keys.
    • # 每個 key 為一行
    • mkdir /home/git/.ssh/
    • chmod 700 /home/git/.ssh/
    •  
    • touch /home/git/.ssh/authorized_keys
    • chmod 600 /home/git/.ssh/authorized_keys
    • chown -R git:git /home/git/.ssh/
    •  
    • # 生成指定用戶的 SSH Key
    • # 在安裝情況下是使用 ssh-keygen -d 生成 dsa
    • # 另還可用 ssh-keygen -t rsa 生成 rsa
    • # 生成時 Enter passphrase 無視按下 enter 即可
    • su username
    • ssh-keygen -d
    • su root
    • cat /home/username/.ssh/id_dsa.pub > /home/git/.ssh/anthorized_keys
    •  
    • # 接著設定 git 的 repo
    • mkdir /home/git/work/test.git
    • cd /home/git/work/test.git && git init --bare --shared
    •  
    • # 接著進行一個簡單的測試
    • mkdir /tmp/test && cd /tmp/test && git init
    • echo "This is a test" > index.html
    • git add
    • git commit -m 'added index.html'
    •  
    • # 之後 commit 到遠端的 repo
    • git remote add origin username@example.com:work/test.git
    • git push origin master
    •  
    • # 之後再設定 gitweb
    • mkdir /home/git/public_html
    • chmod 755 /home/git/public_html
    • chown git:git /home/git/public_html
    • cp /usr/local/share/examples/git/gitweb/git* /home/git/public_html
    •  
    • # 再設定 apache
    • <VirtualHost *:80>
    •   ServerAdmin no-reply@example.com
    •   DocumentRoot "/home/git/public_html"
    •   ServerName git.example.com
    •  
    •   <Directory "/home/git/public_html">
    •     Options ExecCGI
    •     Order allow,deny
    •     Allow from all
    •  
    •     DirectoryIndex gitweb.cgi
    •     AddHandler cgi-script .cgi
    •   </Directory>
    • </VirtualHost>
    •  
    • # 之後再編輯 gitweb.cgi
    • our $projectroot = "/home/git/work";
    • our $home_link_str = "work";
    • our $site_name = "git.example.com"
    • our $projects_list_description_width = 40; # 調整 description 空間
    •  
    • # 修改 test.git 的描述
    • echo "test.git" > /home/git/work/test.git/description
    •  
    • # 修改 test.git 的 owner
    • vim /home/git/work/test.git/config
    •  
    • # 在其後面加入
    • [gitweb]
    • owner = zeuxis
    • url = git://git.example.com/work/test.git
    • url = username@git.example.com:work/test.git
    •  
    • # 最後就是設定 Git protocol
    • # 在 /etc/rc.conf 最後加入這段
    • git_daemon_enable="YES"
    • git_daemon_directory="/home/git"
    • git_daemon_flags="--syslog --base-path=/git --export-all"
    •  
    • # 之後啟動 Git Daemon
    • /usr/local/etc/rc.d/git_daemon start
    •  
    • # 如果以上面這句子會出現停在 starting 的字眼可以改為以下句式
    • # 送出後接兩下 Enter 結束即可
    • /usr/local/etc/rc.d/git_daemon start &
    •  
    • # 檢查是否在執行
    • ps -eaf | grep -v grep | grep git
    •  
    • # 如有東西就可以再測試可否使用了
    • cd /tmp/test
    • rm -Rf *
    • git clone git://git.example.com/work/test.git
    • - See more at: http://www.chair.im/?p=597#sthash.2F0agDtP.W3pF4zk6.dpuf









    • # 先從 devel/git 的 ports 中安裝 git
    • # 同時間選取 gitweb 以提供網頁界面
    • # 之後遇到的設定頁照原來的 OK OK 就可以
    • cd /usr/ports/devel/git
    • make install clean
    •  
    • # 增加 git 的使用者,並指定 git 的家用目錄為 /home/git
    • # 同時間使用 git-shell 作為 shell 指令, uid, gid 為 9418
    • pw groupadd -n git -g 9418
    • pw useradd -n git -u 9418 -g git -c git -d /home/git -s /usr/local/libexec/git-core/git-shell -h -
    •  
    • # 新增 repo (倉庫 work),並更改屬性
    • chown git:git /home/git
    • chmod 755 /home/git
    •  
    • mkdir /home/git/work/
    • chmod 775 /home/git/work/
    • chown git:git /home/git/work/
    •  
    • # 設定除了 commit 外還可以使用額外指令的用戶
    • # 如果使用者只需要 commit,就可以不加進來
    • vi /etc/group
    • git:*:9418:zeuxis,neo
    •  
    • # 設定 SSH 認證金鑰,因為 git 要用到這東西
    • # 每個使用者的 SSH Key 也要加進 authorized_keys.
    • # 每個 key 為一行
    • mkdir /home/git/.ssh/
    • chmod 700 /home/git/.ssh/
    •  
    • touch /home/git/.ssh/authorized_keys
    • chmod 600 /home/git/.ssh/authorized_keys
    • chown -R git:git /home/git/.ssh/
    •  
    • # 生成指定用戶的 SSH Key
    • # 在安裝情況下是使用 ssh-keygen -d 生成 dsa
    • # 另還可用 ssh-keygen -t rsa 生成 rsa
    • # 生成時 Enter passphrase 無視按下 enter 即可
    • su username
    • ssh-keygen -d
    • su root
    • cat /home/username/.ssh/id_dsa.pub > /home/git/.ssh/anthorized_keys
    •  
    • # 接著設定 git 的 repo
    • mkdir /home/git/work/test.git
    • cd /home/git/work/test.git && git init --bare --shared
    •  
    • # 接著進行一個簡單的測試
    • mkdir /tmp/test && cd /tmp/test && git init
    • echo "This is a test" > index.html
    • git add
    • git commit -m 'added index.html'
    •  
    • # 之後 commit 到遠端的 repo
    • git remote add origin username@example.com:work/test.git
    • git push origin master
    •  
    • # 之後再設定 gitweb
    • mkdir /home/git/public_html
    • chmod 755 /home/git/public_html
    • chown git:git /home/git/public_html
    • cp /usr/local/share/examples/git/gitweb/git* /home/git/public_html
    •  
    • # 再設定 apache
    • <VirtualHost *:80>
    •   ServerAdmin no-reply@example.com
    •   DocumentRoot "/home/git/public_html"
    •   ServerName git.example.com
    •  
    •   <Directory "/home/git/public_html">
    •     Options ExecCGI
    •     Order allow,deny
    •     Allow from all
    •  
    •     DirectoryIndex gitweb.cgi
    •     AddHandler cgi-script .cgi
    •   </Directory>
    • </VirtualHost>
    •  
    • # 之後再編輯 gitweb.cgi
    • our $projectroot = "/home/git/work";
    • our $home_link_str = "work";
    • our $site_name = "git.example.com"
    • our $projects_list_description_width = 40; # 調整 description 空間
    •  
    • # 修改 test.git 的描述
    • echo "test.git" > /home/git/work/test.git/description
    •  
    • # 修改 test.git 的 owner
    • vim /home/git/work/test.git/config
    •  
    • # 在其後面加入
    • [gitweb]
    • owner = zeuxis
    • url = git://git.example.com/work/test.git
    • url = username@git.example.com:work/test.git
    •  
    • # 最後就是設定 Git protocol
    • # 在 /etc/rc.conf 最後加入這段
    • git_daemon_enable="YES"
    • git_daemon_directory="/home/git"
    • git_daemon_flags="--syslog --base-path=/git --export-all"
    •  
    • # 之後啟動 Git Daemon
    • /usr/local/etc/rc.d/git_daemon start
    •  
    • # 如果以上面這句子會出現停在 starting 的字眼可以改為以下句式
    • # 送出後接兩下 Enter 結束即可
    • /usr/local/etc/rc.d/git_daemon start &
    •  
    • # 檢查是否在執行
    • ps -eaf | grep -v grep | grep git
    •  
    • # 如有東西就可以再測試可否使用了
    • cd /tmp/test
    • rm -Rf *
    • git clone git://git.example.com/work/test.git
    • - See more at: http://www.chair.im/?p=597#sthash.2F0agDtP.qSAdRJ2D.dpuf









    • # 先從 devel/git 的 ports 中安裝 git
    • # 同時間選取 gitweb 以提供網頁界面
    • # 之後遇到的設定頁照原來的 OK OK 就可以
    • cd /usr/ports/devel/git
    • make install clean
    •  
    • # 增加 git 的使用者,並指定 git 的家用目錄為 /home/git
    • # 同時間使用 git-shell 作為 shell 指令, uid, gid 為 9418
    • pw groupadd -n git -g 9418
    • pw useradd -n git -u 9418 -g git -c git -d /home/git -s /usr/local/libexec/git-core/git-shell -h -
    •  
    • # 新增 repo (倉庫 work),並更改屬性
    • chown git:git /home/git
    • chmod 755 /home/git
    •  
    • mkdir /home/git/work/
    • chmod 775 /home/git/work/
    • chown git:git /home/git/work/
    •  
    • # 設定除了 commit 外還可以使用額外指令的用戶
    • # 如果使用者只需要 commit,就可以不加進來
    • vi /etc/group
    • git:*:9418:zeuxis,neo
    •  
    • # 設定 SSH 認證金鑰,因為 git 要用到這東西
    • # 每個使用者的 SSH Key 也要加進 authorized_keys.
    • # 每個 key 為一行
    • mkdir /home/git/.ssh/
    • chmod 700 /home/git/.ssh/
    •  
    • touch /home/git/.ssh/authorized_keys
    • chmod 600 /home/git/.ssh/authorized_keys
    • chown -R git:git /home/git/.ssh/
    •  
    • # 生成指定用戶的 SSH Key
    • # 在安裝情況下是使用 ssh-keygen -d 生成 dsa
    • # 另還可用 ssh-keygen -t rsa 生成 rsa
    • # 生成時 Enter passphrase 無視按下 enter 即可
    • su username
    • ssh-keygen -d
    • su root
    • cat /home/username/.ssh/id_dsa.pub > /home/git/.ssh/anthorized_keys
    •  
    • # 接著設定 git 的 repo
    • mkdir /home/git/work/test.git
    • cd /home/git/work/test.git && git init --bare --shared
    •  
    • # 接著進行一個簡單的測試
    • mkdir /tmp/test && cd /tmp/test && git init
    • echo "This is a test" > index.html
    • git add
    • git commit -m 'added index.html'
    •  
    • # 之後 commit 到遠端的 repo
    • git remote add origin username@example.com:work/test.git
    • git push origin master
    •  
    • # 之後再設定 gitweb
    • mkdir /home/git/public_html
    • chmod 755 /home/git/public_html
    • chown git:git /home/git/public_html
    • cp /usr/local/share/examples/git/gitweb/git* /home/git/public_html
    •  
    • # 再設定 apache
    • <VirtualHost *:80>
    •   ServerAdmin no-reply@example.com
    •   DocumentRoot "/home/git/public_html"
    •   ServerName git.example.com
    •  
    •   <Directory "/home/git/public_html">
    •     Options ExecCGI
    •     Order allow,deny
    •     Allow from all
    •  
    •     DirectoryIndex gitweb.cgi
    •     AddHandler cgi-script .cgi
    •   </Directory>
    • </VirtualHost>
    •  
    • # 之後再編輯 gitweb.cgi
    • our $projectroot = "/home/git/work";
    • our $home_link_str = "work";
    • our $site_name = "git.example.com"
    • our $projects_list_description_width = 40; # 調整 description 空間
    •  
    • # 修改 test.git 的描述
    • echo "test.git" > /home/git/work/test.git/description
    •  
    • # 修改 test.git 的 owner
    • vim /home/git/work/test.git/config
    •  
    • # 在其後面加入
    • [gitweb]
    • owner = zeuxis
    • url = git://git.example.com/work/test.git
    • url = username@git.example.com:work/test.git
    •  
    • # 最後就是設定 Git protocol
    • # 在 /etc/rc.conf 最後加入這段
    • git_daemon_enable="YES"
    • git_daemon_directory="/home/git"
    • git_daemon_flags="--syslog --base-path=/git --export-all"
    •  
    • # 之後啟動 Git Daemon
    • /usr/local/etc/rc.d/git_daemon start
    •  
    • # 如果以上面這句子會出現停在 starting 的字眼可以改為以下句式
    • # 送出後接兩下 Enter 結束即可
    • /usr/local/etc/rc.d/git_daemon start &
    •  
    • # 檢查是否在執行
    • ps -eaf | grep -v grep | grep git
    •  
    • # 如有東西就可以再測試可否使用了
    • cd /tmp/test
    • rm -Rf *
    • git clone git://git.example.com/work/test.git
    • - See more at: http://www.chair.im/?p=597#sthash.2F0agDtP.qSAdRJ2D.dpuf









    • # 先從 devel/git 的 ports 中安裝 git
    • # 同時間選取 gitweb 以提供網頁界面
    • # 之後遇到的設定頁照原來的 OK OK 就可以
    • cd /usr/ports/devel/git
    • make install clean
    •  
    • # 增加 git 的使用者,並指定 git 的家用目錄為 /home/git
    • # 同時間使用 git-shell 作為 shell 指令, uid, gid 為 9418
    • pw groupadd -n git -g 9418
    • pw useradd -n git -u 9418 -g git -c git -d /home/git -s /usr/local/libexec/git-core/git-shell -h -
    •  
    • # 新增 repo (倉庫 work),並更改屬性
    • chown git:git /home/git
    • chmod 755 /home/git
    •  
    • mkdir /home/git/work/
    • chmod 775 /home/git/work/
    • chown git:git /home/git/work/
    •  
    • # 設定除了 commit 外還可以使用額外指令的用戶
    • # 如果使用者只需要 commit,就可以不加進來
    • vi /etc/group
    • git:*:9418:zeuxis,neo
    •  
    • # 設定 SSH 認證金鑰,因為 git 要用到這東西
    • # 每個使用者的 SSH Key 也要加進 authorized_keys.
    • # 每個 key 為一行
    • mkdir /home/git/.ssh/
    • chmod 700 /home/git/.ssh/
    •  
    • touch /home/git/.ssh/authorized_keys
    • chmod 600 /home/git/.ssh/authorized_keys
    • chown -R git:git /home/git/.ssh/
    •  
    • # 生成指定用戶的 SSH Key
    • # 在安裝情況下是使用 ssh-keygen -d 生成 dsa
    • # 另還可用 ssh-keygen -t rsa 生成 rsa
    • # 生成時 Enter passphrase 無視按下 enter 即可
    • su username
    • ssh-keygen -d
    • su root
    • cat /home/username/.ssh/id_dsa.pub > /home/git/.ssh/anthorized_keys
    •  
    • # 接著設定 git 的 repo
    • mkdir /home/git/work/test.git
    • cd /home/git/work/test.git && git init --bare --shared
    •  
    • # 接著進行一個簡單的測試
    • mkdir /tmp/test && cd /tmp/test && git init
    • echo "This is a test" > index.html
    • git add
    • git commit -m 'added index.html'
    •  
    • # 之後 commit 到遠端的 repo
    • git remote add origin username@example.com:work/test.git
    • git push origin master
    •  
    • # 之後再設定 gitweb
    • mkdir /home/git/public_html
    • chmod 755 /home/git/public_html
    • chown git:git /home/git/public_html
    • cp /usr/local/share/examples/git/gitweb/git* /home/git/public_html
    •  
    • # 再設定 apache
    • <VirtualHost *:80>
    •   ServerAdmin no-reply@example.com
    •   DocumentRoot "/home/git/public_html"
    •   ServerName git.example.com
    •  
    •   <Directory "/home/git/public_html">
    •     Options ExecCGI
    •     Order allow,deny
    •     Allow from all
    •  
    •     DirectoryIndex gitweb.cgi
    •     AddHandler cgi-script .cgi
    •   </Directory>
    • </VirtualHost>
    •  
    • # 之後再編輯 gitweb.cgi
    • our $projectroot = "/home/git/work";
    • our $home_link_str = "work";
    • our $site_name = "git.example.com"
    • our $projects_list_description_width = 40; # 調整 description 空間
    •  
    • # 修改 test.git 的描述
    • echo "test.git" > /home/git/work/test.git/description
    •  
    • # 修改 test.git 的 owner
    • vim /home/git/work/test.git/config
    •  
    • # 在其後面加入
    • [gitweb]
    • owner = zeuxis
    • url = git://git.example.com/work/test.git
    • url = username@git.example.com:work/test.git
    •  
    • # 最後就是設定 Git protocol
    • # 在 /etc/rc.conf 最後加入這段
    • git_daemon_enable="YES"
    • git_daemon_directory="/home/git"
    • git_daemon_flags="--syslog --base-path=/git --export-all"
    •  
    • # 之後啟動 Git Daemon
    • /usr/local/etc/rc.d/git_daemon start
    •  
    • # 如果以上面這句子會出現停在 starting 的字眼可以改為以下句式
    • # 送出後接兩下 Enter 結束即可
    • /usr/local/etc/rc.d/git_daemon start &
    •  
    • # 檢查是否在執行
    • ps -eaf | grep -v grep | grep git
    •  
    • # 如有東西就可以再測試可否使用了
    • cd /tmp/test
    • rm -Rf *
    • git clone git://git.example.com/work/test.git
    • - See more at: http://www.chair.im/?p=597#sthash.2F0agDtP.qSAdRJ2D.dpuf









    • # 先從 devel/git 的 ports 中安裝 git
    • # 同時間選取 gitweb 以提供網頁界面
    • # 之後遇到的設定頁照原來的 OK OK 就可以
    • cd /usr/ports/devel/git
    • make install clean
    •  
    • # 增加 git 的使用者,並指定 git 的家用目錄為 /home/git
    • # 同時間使用 git-shell 作為 shell 指令, uid, gid 為 9418
    • pw groupadd -n git -g 9418
    • pw useradd -n git -u 9418 -g git -c git -d /home/git -s /usr/local/libexec/git-core/git-shell -h -
    •  
    • # 新增 repo (倉庫 work),並更改屬性
    • chown git:git /home/git
    • chmod 755 /home/git
    •  
    • mkdir /home/git/work/
    • chmod 775 /home/git/work/
    • chown git:git /home/git/work/
    •  
    • # 設定除了 commit 外還可以使用額外指令的用戶
    • # 如果使用者只需要 commit,就可以不加進來
    • vi /etc/group
    • git:*:9418:zeuxis,neo
    •  
    • # 設定 SSH 認證金鑰,因為 git 要用到這東西
    • # 每個使用者的 SSH Key 也要加進 authorized_keys.
    • # 每個 key 為一行
    • mkdir /home/git/.ssh/
    • chmod 700 /home/git/.ssh/
    •  
    • touch /home/git/.ssh/authorized_keys
    • chmod 600 /home/git/.ssh/authorized_keys
    • chown -R git:git /home/git/.ssh/
    •  
    • # 生成指定用戶的 SSH Key
    • # 在安裝情況下是使用 ssh-keygen -d 生成 dsa
    • # 另還可用 ssh-keygen -t rsa 生成 rsa
    • # 生成時 Enter passphrase 無視按下 enter 即可
    • su username
    • ssh-keygen -d
    • su root
    • cat /home/username/.ssh/id_dsa.pub > /home/git/.ssh/anthorized_keys
    •  
    • # 接著設定 git 的 repo
    • mkdir /home/git/work/test.git
    • cd /home/git/work/test.git && git init --bare --shared
    •  
    • # 接著進行一個簡單的測試
    • mkdir /tmp/test && cd /tmp/test && git init
    • echo "This is a test" > index.html
    • git add
    • git commit -m 'added index.html'
    •  
    • # 之後 commit 到遠端的 repo
    • git remote add origin username@example.com:work/test.git
    • git push origin master
    •  
    • # 之後再設定 gitweb
    • mkdir /home/git/public_html
    • chmod 755 /home/git/public_html
    • chown git:git /home/git/public_html
    • cp /usr/local/share/examples/git/gitweb/git* /home/git/public_html
    •  
    • # 再設定 apache
    • <VirtualHost *:80>
    •   ServerAdmin no-reply@example.com
    •   DocumentRoot "/home/git/public_html"
    •   ServerName git.example.com
    •  
    •   <Directory "/home/git/public_html">
    •     Options ExecCGI
    •     Order allow,deny
    •     Allow from all
    •  
    •     DirectoryIndex gitweb.cgi
    •     AddHandler cgi-script .cgi
    •   </Directory>
    • </VirtualHost>
    •  
    • # 之後再編輯 gitweb.cgi
    • our $projectroot = "/home/git/work";
    • our $home_link_str = "work";
    • our $site_name = "git.example.com"
    • our $projects_list_description_width = 40; # 調整 description 空間
    •  
    • # 修改 test.git 的描述
    • echo "test.git" > /home/git/work/test.git/description
    •  
    • # 修改 test.git 的 owner
    • vim /home/git/work/test.git/config
    •  
    • # 在其後面加入
    • [gitweb]
    • owner = zeuxis
    • url = git://git.example.com/work/test.git
    • url = username@git.example.com:work/test.git
    •  
    • # 最後就是設定 Git protocol
    • # 在 /etc/rc.conf 最後加入這段
    • git_daemon_enable="YES"
    • git_daemon_directory="/home/git"
    • git_daemon_flags="--syslog --base-path=/git --export-all"
    •  
    • # 之後啟動 Git Daemon
    • /usr/local/etc/rc.d/git_daemon start
    •  
    • # 如果以上面這句子會出現停在 starting 的字眼可以改為以下句式
    • # 送出後接兩下 Enter 結束即可
    • /usr/local/etc/rc.d/git_daemon start &
    •  
    • # 檢查是否在執行
    • ps -eaf | grep -v grep | grep git
    •  
    • # 如有東西就可以再測試可否使用了
    • cd /tmp/test
    • rm -Rf *
    • git clone git://git.example.com/work/test.git
    • - See more at: http://www.chair.im/?p=597#sthash.2F0agDtP.qSAdRJ2D.dpuf









    • # 先從 devel/git 的 ports 中安裝 git
    • # 同時間選取 gitweb 以提供網頁界面
    • # 之後遇到的設定頁照原來的 OK OK 就可以
    • cd /usr/ports/devel/git
    • make install clean
    •  
    • # 增加 git 的使用者,並指定 git 的家用目錄為 /home/git
    • # 同時間使用 git-shell 作為 shell 指令, uid, gid 為 9418
    • pw groupadd -n git -g 9418
    • pw useradd -n git -u 9418 -g git -c git -d /home/git -s /usr/local/libexec/git-core/git-shell -h -
    •  
    • # 新增 repo (倉庫 work),並更改屬性
    • chown git:git /home/git
    • chmod 755 /home/git
    •  
    • mkdir /home/git/work/
    • chmod 775 /home/git/work/
    • chown git:git /home/git/work/
    •  
    • # 設定除了 commit 外還可以使用額外指令的用戶
    • # 如果使用者只需要 commit,就可以不加進來
    • vi /etc/group
    • git:*:9418:zeuxis,neo
    •  
    • # 設定 SSH 認證金鑰,因為 git 要用到這東西
    • # 每個使用者的 SSH Key 也要加進 authorized_keys.
    • # 每個 key 為一行
    • mkdir /home/git/.ssh/
    • chmod 700 /home/git/.ssh/
    •  
    • touch /home/git/.ssh/authorized_keys
    • chmod 600 /home/git/.ssh/authorized_keys
    • chown -R git:git /home/git/.ssh/
    •  
    • # 生成指定用戶的 SSH Key
    • # 在安裝情況下是使用 ssh-keygen -d 生成 dsa
    • # 另還可用 ssh-keygen -t rsa 生成 rsa
    • # 生成時 Enter passphrase 無視按下 enter 即可
    • su username
    • ssh-keygen -d
    • su root
    • cat /home/username/.ssh/id_dsa.pub > /home/git/.ssh/anthorized_keys
    •  
    • # 接著設定 git 的 repo
    • mkdir /home/git/work/test.git
    • cd /home/git/work/test.git && git init --bare --shared
    •  
    • # 接著進行一個簡單的測試
    • mkdir /tmp/test && cd /tmp/test && git init
    • echo "This is a test" > index.html
    • git add
    • git commit -m 'added index.html'
    •  
    • # 之後 commit 到遠端的 repo
    • git remote add origin username@example.com:work/test.git
    • git push origin master
    •  
    • # 之後再設定 gitweb
    • mkdir /home/git/public_html
    • chmod 755 /home/git/public_html
    • chown git:git /home/git/public_html
    • cp /usr/local/share/examples/git/gitweb/git* /home/git/public_html
    •  
    • # 再設定 apache
    • <VirtualHost *:80>
    •   ServerAdmin no-reply@example.com
    •   DocumentRoot "/home/git/public_html"
    •   ServerName git.example.com
    •  
    •   <Directory "/home/git/public_html">
    •     Options ExecCGI
    •     Order allow,deny
    •     Allow from all
    •  
    •     DirectoryIndex gitweb.cgi
    •     AddHandler cgi-script .cgi
    •   </Directory>
    • </VirtualHost>
    •  
    • # 之後再編輯 gitweb.cgi
    • our $projectroot = "/home/git/work";
    • our $home_link_str = "work";
    • our $site_name = "git.example.com"
    • our $projects_list_description_width = 40; # 調整 description 空間
    •  
    • # 修改 test.git 的描述
    • echo "test.git" > /home/git/work/test.git/description
    •  
    • # 修改 test.git 的 owner
    • vim /home/git/work/test.git/config
    •  
    • # 在其後面加入
    • [gitweb]
    • owner = zeuxis
    • url = git://git.example.com/work/test.git
    • url = username@git.example.com:work/test.git
    •  
    • # 最後就是設定 Git protocol
    • # 在 /etc/rc.conf 最後加入這段
    • git_daemon_enable="YES"
    • git_daemon_directory="/home/git"
    • git_daemon_flags="--syslog --base-path=/git --export-all"
    •  
    • # 之後啟動 Git Daemon
    • /usr/local/etc/rc.d/git_daemon start
    •  
    • # 如果以上面這句子會出現停在 starting 的字眼可以改為以下句式
    • # 送出後接兩下 Enter 結束即可
    • /usr/local/etc/rc.d/git_daemon start &
    •  
    • # 檢查是否在執行
    • ps -eaf | grep -v grep | grep git
    •  
    • # 如有東西就可以再測試可否使用了
    • cd /tmp/test
    • rm -Rf *
    • git clone git://git.example.com/work/test.git
    • - See more at: http://www.chair.im/?p=597#sthash.2F0agDtP.qSAdRJ2D.dpuf









    • # 先從 devel/git 的 ports 中安裝 git
    • # 同時間選取 gitweb 以提供網頁界面
    • # 之後遇到的設定頁照原來的 OK OK 就可以
    • cd /usr/ports/devel/git
    • make install clean
    •  
    • # 增加 git 的使用者,並指定 git 的家用目錄為 /home/git
    • # 同時間使用 git-shell 作為 shell 指令, uid, gid 為 9418
    • pw groupadd -n git -g 9418
    • pw useradd -n git -u 9418 -g git -c git -d /home/git -s /usr/local/libexec/git-core/git-shell -h -
    •  
    • # 新增 repo (倉庫 work),並更改屬性
    • chown git:git /home/git
    • chmod 755 /home/git
    •  
    • mkdir /home/git/work/
    • chmod 775 /home/git/work/
    • chown git:git /home/git/work/
    •  
    • # 設定除了 commit 外還可以使用額外指令的用戶
    • # 如果使用者只需要 commit,就可以不加進來
    • vi /etc/group
    • git:*:9418:zeuxis,neo
    •  
    • # 設定 SSH 認證金鑰,因為 git 要用到這東西
    • # 每個使用者的 SSH Key 也要加進 authorized_keys.
    • # 每個 key 為一行
    • mkdir /home/git/.ssh/
    • chmod 700 /home/git/.ssh/
    •  
    • touch /home/git/.ssh/authorized_keys
    • chmod 600 /home/git/.ssh/authorized_keys
    • chown -R git:git /home/git/.ssh/
    •  
    • # 生成指定用戶的 SSH Key
    • # 在安裝情況下是使用 ssh-keygen -d 生成 dsa
    • # 另還可用 ssh-keygen -t rsa 生成 rsa
    • # 生成時 Enter passphrase 無視按下 enter 即可
    • su username
    • ssh-keygen -d
    • su root
    • cat /home/username/.ssh/id_dsa.pub > /home/git/.ssh/anthorized_keys
    •  
    • # 接著設定 git 的 repo
    • mkdir /home/git/work/test.git
    • cd /home/git/work/test.git && git init --bare --shared
    •  
    • # 接著進行一個簡單的測試
    • mkdir /tmp/test && cd /tmp/test && git init
    • echo "This is a test" > index.html
    • git add
    • git commit -m 'added index.html'
    •  
    • # 之後 commit 到遠端的 repo
    • git remote add origin username@example.com:work/test.git
    • git push origin master
    •  
    • # 之後再設定 gitweb
    • mkdir /home/git/public_html
    • chmod 755 /home/git/public_html
    • chown git:git /home/git/public_html
    • cp /usr/local/share/examples/git/gitweb/git* /home/git/public_html
    •  
    • # 再設定 apache
    • <VirtualHost *:80>
    •   ServerAdmin no-reply@example.com
    •   DocumentRoot "/home/git/public_html"
    •   ServerName git.example.com
    •  
    •   <Directory "/home/git/public_html">
    •     Options ExecCGI
    •     Order allow,deny
    •     Allow from all
    •  
    •     DirectoryIndex gitweb.cgi
    •     AddHandler cgi-script .cgi
    •   </Directory>
    • </VirtualHost>
    •  
    • # 之後再編輯 gitweb.cgi
    • our $projectroot = "/home/git/work";
    • our $home_link_str = "work";
    • our $site_name = "git.example.com"
    • our $projects_list_description_width = 40; # 調整 description 空間
    •  
    • # 修改 test.git 的描述
    • echo "test.git" > /home/git/work/test.git/description
    •  
    • # 修改 test.git 的 owner
    • vim /home/git/work/test.git/config
    •  
    • # 在其後面加入
    • [gitweb]
    • owner = zeuxis
    • url = git://git.example.com/work/test.git
    • url = username@git.example.com:work/test.git
    •  
    • # 最後就是設定 Git protocol
    • # 在 /etc/rc.conf 最後加入這段
    • git_daemon_enable="YES"
    • git_daemon_directory="/home/git"
    • git_daemon_flags="--syslog --base-path=/git --export-all"
    •  
    • # 之後啟動 Git Daemon
    • /usr/local/etc/rc.d/git_daemon start
    •  
    • # 如果以上面這句子會出現停在 starting 的字眼可以改為以下句式
    • # 送出後接兩下 Enter 結束即可
    • /usr/local/etc/rc.d/git_daemon start &
    •  
    • # 檢查是否在執行
    • ps -eaf | grep -v grep | grep git
    •  
    • # 如有東西就可以再測試可否使用了
    • cd /tmp/test
    • rm -Rf *
    • git clone git://git.example.com/work/test.git
    • - See more at: http://www.chair.im/?p=597#sthash.2F0agDtP.qSAdRJ2D.dpuf









    • # 先從 devel/git 的 ports 中安裝 git
    • # 同時間選取 gitweb 以提供網頁界面
    • # 之後遇到的設定頁照原來的 OK OK 就可以
    • cd /usr/ports/devel/git
    • make install clean
    •  
    • # 增加 git 的使用者,並指定 git 的家用目錄為 /home/git
    • # 同時間使用 git-shell 作為 shell 指令, uid, gid 為 9418
    • pw groupadd -n git -g 9418
    • pw useradd -n git -u 9418 -g git -c git -d /home/git -s /usr/local/libexec/git-core/git-shell -h -
    •  
    • # 新增 repo (倉庫 work),並更改屬性
    • chown git:git /home/git
    • chmod 755 /home/git
    •  
    • mkdir /home/git/work/
    • chmod 775 /home/git/work/
    • chown git:git /home/git/work/
    •  
    • # 設定除了 commit 外還可以使用額外指令的用戶
    • # 如果使用者只需要 commit,就可以不加進來
    • vi /etc/group
    • git:*:9418:zeuxis,neo
    •  
    • # 設定 SSH 認證金鑰,因為 git 要用到這東西
    • # 每個使用者的 SSH Key 也要加進 authorized_keys.
    • # 每個 key 為一行
    • mkdir /home/git/.ssh/
    • chmod 700 /home/git/.ssh/
    •  
    • touch /home/git/.ssh/authorized_keys
    • chmod 600 /home/git/.ssh/authorized_keys
    • chown -R git:git /home/git/.ssh/
    •  
    • # 生成指定用戶的 SSH Key
    • # 在安裝情況下是使用 ssh-keygen -d 生成 dsa
    • # 另還可用 ssh-keygen -t rsa 生成 rsa
    • # 生成時 Enter passphrase 無視按下 enter 即可
    • su username
    • ssh-keygen -d
    • su root
    • cat /home/username/.ssh/id_dsa.pub > /home/git/.ssh/anthorized_keys
    •  
    • # 接著設定 git 的 repo
    • mkdir /home/git/work/test.git
    • cd /home/git/work/test.git && git init --bare --shared
    •  
    • # 接著進行一個簡單的測試
    • mkdir /tmp/test && cd /tmp/test && git init
    • echo "This is a test" > index.html
    • git add
    • git commit -m 'added index.html'
    •  
    • # 之後 commit 到遠端的 repo
    • git remote add origin username@example.com:work/test.git
    • git push origin master
    •  
    • # 之後再設定 gitweb
    • mkdir /home/git/public_html
    • chmod 755 /home/git/public_html
    • chown git:git /home/git/public_html
    • cp /usr/local/share/examples/git/gitweb/git* /home/git/public_html
    •  
    • # 再設定 apache
    • <VirtualHost *:80>
    •   ServerAdmin no-reply@example.com
    •   DocumentRoot "/home/git/public_html"
    •   ServerName git.example.com
    •  
    •   <Directory "/home/git/public_html">
    •     Options ExecCGI
    •     Order allow,deny
    •     Allow from all
    •  
    •     DirectoryIndex gitweb.cgi
    •     AddHandler cgi-script .cgi
    •   </Directory>
    • </VirtualHost>
    •  
    • # 之後再編輯 gitweb.cgi
    • our $projectroot = "/home/git/work";
    • our $home_link_str = "work";
    • our $site_name = "git.example.com"
    • our $projects_list_description_width = 40; # 調整 description 空間
    •  
    • # 修改 test.git 的描述
    • echo "test.git" > /home/git/work/test.git/description
    •  
    • # 修改 test.git 的 owner
    • vim /home/git/work/test.git/config
    •  
    • # 在其後面加入
    • [gitweb]
    • owner = zeuxis
    • url = git://git.example.com/work/test.git
    • url = username@git.example.com:work/test.git
    •  
    • # 最後就是設定 Git protocol
    • # 在 /etc/rc.conf 最後加入這段
    • git_daemon_enable="YES"
    • git_daemon_directory="/home/git"
    • git_daemon_flags="--syslog --base-path=/git --export-all"
    •  
    • # 之後啟動 Git Daemon
    • /usr/local/etc/rc.d/git_daemon start
    •  
    • # 如果以上面這句子會出現停在 starting 的字眼可以改為以下句式
    • # 送出後接兩下 Enter 結束即可
    • /usr/local/etc/rc.d/git_daemon start &
    •  
    • # 檢查是否在執行
    • ps -eaf | grep -v grep | grep git
    •  
    • # 如有東西就可以再測試可否使用了
    • cd /tmp/test
    • rm -Rf *
    • git clone git://git.example.com/work/test.git
    • - See more at: http://www.chair.im/?p=597#sthash.2F0agDtP.qSAdRJ2D.dpuf









    • # 先從 devel/git 的 ports 中安裝 git
    • # 同時間選取 gitweb 以提供網頁界面
    • # 之後遇到的設定頁照原來的 OK OK 就可以
    • cd /usr/ports/devel/git
    • make install clean
    •  
    • # 增加 git 的使用者,並指定 git 的家用目錄為 /home/git
    • # 同時間使用 git-shell 作為 shell 指令, uid, gid 為 9418
    • pw groupadd -n git -g 9418
    • pw useradd -n git -u 9418 -g git -c git -d /home/git -s /usr/local/libexec/git-core/git-shell -h -
    •  
    • # 新增 repo (倉庫 work),並更改屬性
    • chown git:git /home/git
    • chmod 755 /home/git
    •  
    • mkdir /home/git/work/
    • chmod 775 /home/git/work/
    • chown git:git /home/git/work/
    •  
    • # 設定除了 commit 外還可以使用額外指令的用戶
    • # 如果使用者只需要 commit,就可以不加進來
    • vi /etc/group
    • git:*:9418:zeuxis,neo
    •  
    • # 設定 SSH 認證金鑰,因為 git 要用到這東西
    • # 每個使用者的 SSH Key 也要加進 authorized_keys.
    • # 每個 key 為一行
    • mkdir /home/git/.ssh/
    • chmod 700 /home/git/.ssh/
    •  
    • touch /home/git/.ssh/authorized_keys
    • chmod 600 /home/git/.ssh/authorized_keys
    • chown -R git:git /home/git/.ssh/
    •  
    • # 生成指定用戶的 SSH Key
    • # 在安裝情況下是使用 ssh-keygen -d 生成 dsa
    • # 另還可用 ssh-keygen -t rsa 生成 rsa
    • # 生成時 Enter passphrase 無視按下 enter 即可
    • su username
    • ssh-keygen -d
    • su root
    • cat /home/username/.ssh/id_dsa.pub > /home/git/.ssh/anthorized_keys
    •  
    • # 接著設定 git 的 repo
    • mkdir /home/git/work/test.git
    • cd /home/git/work/test.git && git init --bare --shared
    •  
    • # 接著進行一個簡單的測試
    • mkdir /tmp/test && cd /tmp/test && git init
    • echo "This is a test" > index.html
    • git add
    • git commit -m 'added index.html'
    •  
    • # 之後 commit 到遠端的 repo
    • git remote add origin username@example.com:work/test.git
    • git push origin master
    •  
    • # 之後再設定 gitweb
    • mkdir /home/git/public_html
    • chmod 755 /home/git/public_html
    • chown git:git /home/git/public_html
    • cp /usr/local/share/examples/git/gitweb/git* /home/git/public_html
    •  
    • # 再設定 apache
    • <VirtualHost *:80>
    •   ServerAdmin no-reply@example.com
    •   DocumentRoot "/home/git/public_html"
    •   ServerName git.example.com
    •  
    •   <Directory "/home/git/public_html">
    •     Options ExecCGI
    •     Order allow,deny
    •     Allow from all
    •  
    •     DirectoryIndex gitweb.cgi
    •     AddHandler cgi-script .cgi
    •   </Directory>
    • </VirtualHost>
    •  
    • # 之後再編輯 gitweb.cgi
    • our $projectroot = "/home/git/work";
    • our $home_link_str = "work";
    • our $site_name = "git.example.com"
    • our $projects_list_description_width = 40; # 調整 description 空間
    •  
    • # 修改 test.git 的描述
    • echo "test.git" > /home/git/work/test.git/description
    •  
    • # 修改 test.git 的 owner
    • vim /home/git/work/test.git/config
    •  
    • # 在其後面加入
    • [gitweb]
    • owner = zeuxis
    • url = git://git.example.com/work/test.git
    • url = username@git.example.com:work/test.git
    •  
    • # 最後就是設定 Git protocol
    • # 在 /etc/rc.conf 最後加入這段
    • git_daemon_enable="YES"
    • git_daemon_directory="/home/git"
    • git_daemon_flags="--syslog --base-path=/git --export-all"
    •  
    • # 之後啟動 Git Daemon
    • /usr/local/etc/rc.d/git_daemon start
    •  
    • # 如果以上面這句子會出現停在 starting 的字眼可以改為以下句式
    • # 送出後接兩下 Enter 結束即可
    • /usr/local/etc/rc.d/git_daemon start &
    •  
    • # 檢查是否在執行
    • ps -eaf | grep -v grep | grep git
    •  
    • # 如有東西就可以再測試可否使用了
    • cd /tmp/test
    • rm -Rf *
    • git clone git://git.example.com/work/test.git
    • - See more at: http://www.chair.im/?p=597#sthash.2F0agDtP.qSAdRJ2D.dpuf

      • You can clone and push your repository by http://yourdomain2/gitweb/sademo.git and password is your student id.
      做到這邊已經可以用 git 的 protocol 來 clone & push 了 (git clone git@git.example.com:github/sademo.git),但是因為他要求要用 http 的 protocol 所以要稍微改一下


      Reference:
      gitweb manual:
      http://www.jedi.be/blog/2009/05/06/8-ways-to-share-your-git-repository/#apachehttp
      https://www.kernel.org/pub/software/scm/git/docs/gitweb.html
      • Users use cookie authentication when access your phpMyAdmin site http://yourdomain1/phpMyAdmin/
        • (You need to add a MySQL user for authentication).
        • Create another user with limited privilege
        • And notice that if others access http://yourdomain2/phpMyAdmin/, they can not access it.
        • Only 140.113.*.* can access it
        • But 140.113.235.* can’t access it
      基本上只要裝好 phpMyAdmin 然後在 httpd.conf 裏面加入

      Alias /phpMyAdmin /usr/local/www/phpMyAdmin

      然後因為要求只有 domain1 才能到 phpMyAdmin,所以就在 Virtualhost domain 1 的地方加上條件限制,接著修改 /usr/local/www/phpMyAdmin/config.inc.php 的設定檔(複製同目錄底下的 config.sample.inc.php 到 config.inc.php)

      首先先更改 root 密碼:

      mysqladmin -u root password

      接著就要增加 MySQL 的 user

      mysql -u root -p

      mysql> create user 'username'@'localhost';
      mysql> set password for 'username'@'localhost' = PASSWORD('password');

      因為他說要被限制,所以就隨便開個東西的權限給他其他就會被限制了

      mysql> grant trigger on db1.* to 'username'@'localhost';


      Reference:
      phpMyAdmin: 
      MySQL:
      http://www.weithenn.org/cgi-bin/wiki.pl?Mysql_Apache_PHP-%E9%BB%83%E9%87%91%E6%9E%B6%E7%AB%99%E7%B5%84%E5%90%88
      create user:
      http://dev.mysql.com/doc/refman/5.1/en/create-user.html
      grant: (permission)
      http://dev.mysql.com/doc/refman/5.1/en/grant.html 

      • Redirect http://yourdomain1/ILoveSA to http://help.cs.nctu.edu.tw/ 
        • But http://yourdomain2/ILoveSA will not redirect .

      修改 /usr/local/etc/apache22/extra/httpd-vhosts.conf 在 virtual host domain 1 的地方加入:

      Redirect /ILoveSA http://help.cs.nctu.edu.tw/


      MySQL: 
      http://linux.vbird.org/linux_server/0360apache.php#www_basic_mysql
      http://neroli.pixnet.net/blog/post/32287589-%5Bfreebsd%5D-apache%2Bphp%2Bmysql%E5%AE%89%E8%A3%9D%E8%88%87%E8%A8%AD%E5%AE%9A
      remove database:
      http://dev.mysql.com/doc/refman/5.5/en/drop-database.html




      沒有留言:

      張貼留言