最近準備移機和備份資料,雖然把開發環境跟 Trac 綁在一起不是很好,但基於機器數量及資源管理方面,備份就暫且這樣吧 :P 目標:有 Django 環境、有 Trac 環境,其中 Trac 採用 Subversion 並提供 HTTP 存取方式,並且讓 Subversion 和 Trac 的帳密使用同一份。
安裝相關環境:
$ sudo apt-get install mysql-server apache2 subversion libapache2-mod-python libapache2-svn libapache2-mod-wsgi python-mysqldb python-django ipython trac
設定 Subversion 環境:
挑選 /var/svn/repository 目錄為例
$ sudo mkdir -p /var/svn/repository
$ sudo chown -R www-data:www-data /var/svn/repository
建立一個 Trac 環境:
挑選 /var/local/trac 目錄為例
$ sudo mkdir -p /var/local/trac
$ sudo chown -R www-data:www-data /var/local/trac
設定 Apache Web Server 環境:
設定檔位置以 /etc/apache2/ 為例
設定帳密:
$ sudo touch /etc/apache2/dav_svn.passwd
$ sudo htpasswd /etc/apache2/dav_svn.passwd username
設定 Subversion 部份:
可以挑選 /etc/apache2/mods-available/dav_svn.conf 和 a2enmod
此例用 /etc/apache2/site-available/svn.conf 和 a2ensite
$ sudo vim /etc/apache2/site-available/svn.conf
<IfModule !dav_svn_module>
LoadModule dav_svn_module modules/mod_dav_svn.so
</IfModule>
<IfModule !authz_svn_module>
LoadModule authz_svn_module modules/mod_authz_svn.so
</IfModule>
<IfModule dav_svn_module>
<IfModule authz_svn_module>
<Location /svn>
DAV svn
SVNParentPath /var/svn/repository
AuthType Basic
AuthName "Subversion Repository"
AuthUserFile /etc/apache2/dav_svn.passwd
Require valid-user
</Location>
</IfModule>
</IfModule>
$ sudo a2ensite svn.conf
$ sudo /etc/init.d/apache2 reload
如此一來,提供 http://localhost/svn/ProjectName 的存取機制,並採用 dav_svn.passwd 帳密管理
設定 Trac 部份:
可以挑選 /etc/apache2/mods-available/trac.conf 和 a2enmod
此例用 /etc/apache2/sites-available/trac.conf 和 a2ensite
$ sudo vim /etc/apache2/site-available/trac.conf
<IfModule !python_module>
LoadModule python_module modules/mod_python.so
</IfModule>
<IfModule python_module>
<location /projects>
SetHandler mod_python
PythonHandler trac.web.modpython_frontend
PythonOption TracEnvParentDir /var/local/trac
PythonOption TracUriRoot /projects
</location>
<locationmatch "/projects/[^/]+/login">
AuthType Basic
AuthName "Trac Authentication"
AuthUserFile /etc/apache2/dav_svn.passwd
Require valid-user
</locationmatch>
</IfModule>
$ sudo a2ensite trac.conf
$ sudo /etc/init.d/apache2 reload
如此一來瀏覽 http://localhost/projects 就可以看到 Trac 清單,並且登入各個 Trac Project 時,採用 dav_svn.passwd 帳密管理
建立一個 Project:
建立 Subversion project:
$ sudo -u www-data svnadmin create /var/svn/repository/mysite
建立 Trac project:
$ sudo -u www-data trac-admin /var/local/trac/mysite initenv
Project Name [My Project]> mysite
Database connection string [sqlite:db/trac.db]>
Repository type [svn]>
Path to repository [/path/to/repos]> /var/svn/repository/mysite
建立 mysite Trac 管理者(須先建立於 /etc/apache2/dav_svn.passwd 中):
$ sudo -u www-data trac-admin /var/local/trac/mysite/ permission add username TRAC_ADMIN
如此一來,就可以從 http://localhost/projects/mysite 進入 Trac 了,更可以用 username 登入後進去 Trac 管理者頁面進行設定,例如把 anonymous 權限刪掉,或是修改 authenticated 的權限,限制成員以外的只能 WIKI_VIEW 等,如果想要限制使用者能觀看哪些 page 的話,那可以試試 plugin TracTags 和 TracFullBlogPlugin 等。
挑選 ~/projects 目錄為例,作為儲存程式碼的地方:
$ mkdir ~/projects
建立 Django Project:
$ cd ~/projects
$ django-admin startproject mysite
$ cd ~/projects/mysite
$ django-admin startapp myapp
測試連線:
$ python manage.py runserver 0.0.0.0:8000
設定 Django 採用 WSGI 啟動(可隨著 Apache Web Server 啟動關閉一起行動):
此例用 /etc/apache2/sites-available/mysite.conf 和 a2ensite
建立 django.wsgi:
$ vim ~/projects/mysite/django-mysite.wsgi
import os, sys
sys.path.append('/home/user/projects')
sys.path.append('/home/user/projects/mysite')
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
設定 mysite apache:
以 Port 做為區分服務的機制,此例為 port 8000
$ sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/mysite
$ sudo vim /etc/apache2/sites-available/mysite
Listen 8000
<VirtualHost *:8000>
WSGIScriptAlias / /home/user/projects/mysite/django-mysite.wsgi
WSGIDaemonProcess mysite_demo user=user group=user processes=1 threads=10
ServerAdmin webmaster@localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
$ sudo a2ensite mysite
$ sudo /etc/init.d/apache2 reload
存入 Subversion project:
$ cd ~/projects/
$ svn co http://localhost/svn/mysite svn_mysite
$ mkdir ~/projects/svn_mysite/trunk
$ mv ~/projects/mysite/* ~/projects/svn_mysite/trunk
$ cd ~/projects/svn_mysite
$ svn add trunk
$ svn ci -m 'init django project'
$ cd ~/projects
$ svn co http://localhost/svn/mysite/trunk mysite
$ rm -rf ~/projects/svn_mysite
$ cd ~/projects/mysite
$ svn info
Path: .
URL: http://localhost/svn/mysite/trunk
Repository Root: http://localhost/svn/mysite
Repository UUID: ########-####-####-####-##########
Revision: 1
Node Kind: directory
Schedule: normal
Last Changed Author: user
Last Changed Rev: 1
Last Changed Date: 2011-12-08 21:00:00 +0800 (Thu, 08 Dec 2011)
匯入:
$ sudo cp -r your_trac_project /var/local/trac
$ sudo cp -r toyr_svn_project /var/svn/repository/
$ sudo chown -R www-data:www-data /var/local/trac /var/svn/repository/
Update Path info:
/var/local/trac/*/conf/trac.ini
authz_file = /var/local/trac/*/conf/authzpolicy.conf
收工!
沒有留言:
張貼留言