以前做一些小的项目,没有怎么用到svn之类的版本控制软件,因为项目本身就很小,几十个文件,基本上也没有太多的改动。所以都是采用直接备份文件方式来防止工作间的文件丢失。
这次自己想做的一个小东西,虽然不大,但是希望把开发过程正规起来,不能总是采用远古的作坊式了,为了直接一步和国际流行的开发方式接轨,这次我直接使用了目前比较流行的源代码浏览工具–trac。下面是我的配置过程,和大家分享。
- 首先需要配置SVN,这是核心和基础,只有设置好了SVN才有可能做下面的过程。
不过SVN还是挺好用的,步骤也简洁:
[root@mlsx home]#svnadmin create /data/ytqpki [root@mlsx home]#svn import /var/www/html/app file:///data/ytqpki -m "initial" 新增 /var/www/html/app/vendors 新增 /var/www/html/app/vendors/empty 新增 /var/www/html/app/tmp 新增 /var/www/html/app/tmp/tests ...............
第一个命令创建仓库,第二个命令导入初始化的文件。 当然你还可以继续导入,导入后,源文件就可以删除了。
这是建立仓库的过程,如果要开始编写代码,你还需要创建自己的第一个版本代码,也就是到处一份程序。
[root@mlsx home]# svn co file:///data/ytqpki /home/htdocs/
A /home/htdocs/app
A /home/htdocs/app/tmp
A /home/htdocs/app/tmp/tests
A /home/htdocs/app/tmp/tests/empty
A /home/htdocs/app/tmp/cache
……
/home/htdocs/就是现在的工作目录了,所有代码的增加修改都在这里执行,需要提交,就使用svn up,svn add,svn
ci。更多的使用方法可以参考有关SVN的指南。
安装和配置apache+svn
对于Linux系统而言,apache都是预安装好了,不过需要检查是否安装了mod_dav_svn这个模块,如果没有,需要安装上。注意:mod_dav_svn模块的版本号应该和subversion的版本号一致。
安装完成后,编辑/etc/httpd/conf.d/subversion.conf文件,再最后加上下面几行DAV svn SVNParentPath /data # # # Limit write permission to list of valid users. # Require SSL connection for password protection. # SSLRequireSSL # AuthType Basic AuthName “Authorization Realm” AuthUserFile /etc/svnpwdfile Require valid-user
然后,我们htpasswd创建/etc/svnpawdfile文件
[root@mlsx ~]# htpasswd -c /etc/snvpwdfile admin
New password:
Re-type new password:
Adding password for user admin
[root@mlsx ~]# htpasswd /etc/snvpwdfile mlsx
New password:
Re-type new password:
Adding password for user mlsx
OK,现在重启你的apache,访问http://localhost/repos/ytqpki看看。
如果得到下面类似的界面,那么svn访问表示成功了。

这个时候,你也可以使用通过http方式取得svn仓库内的文档了。
[root@mlsx ~]# svn co http://localhost/repos/ytqpki/app /tmp/
A /tmp/tmp
A /tmp/tmp/tests
A /tmp/tmp/tests/empty
A /tmp/tmp/cache
A /tmp/tmp/cache/persistent
A /tmp/tmp/cache/persistent/empty
A /tmp/tmp/cache/models
A /tmp/tmp/cache/models/default_admins
…….
配置trac trac是一个非常优秀的源代码浏览工具,现在也很流行。
安装trac之前,还需要安装一些其他东西,首先是python,这个一般都安装了,其次是ClearSilver,最后是一个能够被python支持的数据库,默认是SQLite。 上面的要求,一般来说,只有ClearSilver没有安装,下载最新的版本,分别执行./configure --with-python=/usr/bin/python ; make; make install就搞定了。
然后下载最新的trac程序,解压,执行下面的指令
./setup.py install
安装完成后,开始配置[root@mlsx trac-0.10.4]# trac-admin /home/ytqpki initenv Creating a new Trac environment at /home/ytqpki Trac will first ask a few questions about your environment in order to initalize and prepare the project database. Please enter the name of your project. This name will be used in page titles and descriptions. Project Name [My Project]> ytqpki Please specify the connection string for the database to use. By default, a local SQLite database is created in the environment directory. It is also possible to use an already existing PostgreSQL database (check the Trac documentation for the exact connection string syntax). Database connection string [sqlite:db/trac.db]> Please specify the type of version control system, By default, it will be svn. If you don't want to use Trac with version control integration, choose the default here and don't specify a repository directory. in the next question. Repository type [svn]> Please specify the absolute path to the version control repository, or leave it blank to use Trac without a repository. You can also set the repository location later. Path to repository [/path/to/repos]> /data/ytqpki Please enter location of Trac page templates. Default is the location of the site-wide templates installed with Trac. Templates directory [/usr/share/trac/templates]> Creating and Initializing Project Installing default wiki pages /usr/share/trac/wiki-default/TracFastCgi => TracFastCgi /usr/share/trac/wiki-default/TracIni => TracIni /usr/share/trac/wiki-default/TracReports => TracReports /usr/share/trac/wiki-default/TracTickets => TracTickets /usr/share/trac/wiki-default/TracSearch => TracSearch /usr/share/trac/wiki-default/TracModPython => TracModPython /usr/share/trac/wiki-default/WikiRestructuredTextLinks => WikiRestructuredTextLinks /usr/share/trac/wiki-default/InterTrac => InterTrac /usr/share/trac/wiki-default/CamelCase => CamelCase /usr/share/trac/wiki-default/TracBrowser => TracBrowser /usr/share/trac/wiki-default/WikiNewPage => WikiNewPage /usr/share/trac/wiki-default/TracAccessibility => TracAccessibility /usr/share/trac/wiki-default/InterWiki => InterWiki /usr/share/trac/wiki-default/TracNotification => TracNotification /usr/share/trac/wiki-default/TracLinks => TracLinks /usr/share/trac/wiki-default/TracCgi => TracCgi /usr/share/trac/wiki-default/TracRevisionLog => TracRevisionLog /usr/share/trac/wiki-default/WikiFormatting => WikiFormatting /usr/share/trac/wiki-default/TracAdmin => TracAdmin Warning: You should install the SVN bindings ——————————————————————— Project environment for 'ytqpki' created. You may now configure the environment by editing the file: /home/ytqpki/conf/trac.ini If you'd like to take this new project environment for a test drive, try running the Trac standalone web server `tracd`: tracd –port 8000 /home/ytqpki Then point your browser to http://localhost:8000/ytqpki. There you can also browse the documentation for your installed version of Trac, including information on further setup (such as deploying Trac to a real web server). The latest documentation can also always be found on the project website: http://trac.edgewall.org/ Congratulations!
如果最后出现类似上面的信息,表示配置成功,trac可以独立运行,也可以集成到apache里,我们先看独立运行的方式
tracd --port 8000 /home/ytqpki
打开浏览器,访问http://localhost:8000/ytqpki
应该可以trac的默认首页,类似下面这样:

集成trac到apache
把trac集成的到apache有很多方法,可以使用mod_python模块,可以使用cgi模块或者fast-cgi模块.mod_python我配置了一下,没有成功,于是改用了cgi模式
这个方法比较简单.如果你需要速度快一点,那使用fast-cgi好了.
首先把trac源代码目录中cgi-bin目下的两个文件拷贝到你期望的地方,比如/var/www/cgi-bin.我这里是放到/home/cgi-bin目录下的. 然后增加/etc/httpd/conf.d/trac.conf文件,内容如下ScriptAlias /trac /home/cgi-bin/trac.fcgi # Trac needs to know where the database is located SetEnv TRAC_ENV /home/ytqpki AuthType Basic AuthName “Trac” AuthUserFile /etc/svnpwdfile Require valid-user
如果你使用的是cgi模式,那么把第一行的trac.fcgi,修改成trac.cgi
密码文件我们和svn共享,这样就只需要管理一套密码了.
保存,退出,重启apache.再访问http://localhost/trac看看是不是可以得到trac的默认首页,然后点击”browse
source”,你应该可以看到svn仓库里的资源.类似下面这样

随便点击一个源代码文件,可以得到类似下面的界面

不知道是不是需要继续配置,浏览源代码时,源代码里的中文不能显示.
到此,全部配置完成,当然这都是采用最简单,缺省的方式配置起来的,有关授权访问没有细化,不过这都是一些再细化的工作了,至少框架搭建起来了. 再配合支持svn的开发工具,比如Eclipse,Komodo,开发起来还是比较有安全感的.