---
title: "linux下httpd-2.2.6 + svn 1.4.5+ php5.2.5"
author: "PBFox"
date: "2008-01-09T08:56:00Z"
tags: []
slug: "linux-httpd-2-2-6-svn-1-4-5-php5-2-5"
draft: false
lastmod: "2008-01-09T08:56:00Z"
id: 479238
url: "https://developerwork.iteye.com/blog/479238"
---

安装需要的软件包：  
Apr ：APR-1.2.12和APR-util-1.2.12  
Apache ：httpd-2.2.6.tar.gz  
Subversion：subversion-1.4.5.tar.gz subversion-deps-1.4.5.tar.gz  
Php ：php-5.2.5.tar.gz  
Php支持库：libxml2-2.6.19.tar.gz  
1、安装APR-1.2.12和APR-util-1.2.12  
1\) #tar zxvfapr-1.2.12.tar.gz  
#cd apr-1.2.12  
#./configure  
Make;make install  
2\) #tar zxvf apr-util-1.2.12.tar.gz  
#cd apr-util-1.2.12  
#. /configure --with-apr=/usr/local/apr  
#make;make install  
2、安装apache 2.2.6  
1）解包 httpd-2.2.6.tar.gz  
#tar xzvf httpd-2.2.6.tar.gz  
2\) 生成配置文件  
#./configure --prefix=/usr/local/apache2 --enable-dav --enable-modules=so --enable-maintainer-mode --enable-rewrite --with-apr=/usr/local/apr/bin/apr-1-config --with-apr-util=/usr/local/apr/bin/apu-1-config  
3）生成make文件，并安装  
#make；makeinstall  
4）编辑配置文件httpd.conf  
\# vi /usr/local/apache2/conf/httpd.conf  
修改内容：  
ServerName [www.example.com:80](http://www.example.com/)  
ServerName localhost:80  
保存退出  
5）启动Apache服务：  
\# /usr/local/apache2/bin/apachectl start  
6）浏览网站：  
用浏览器查看http://localhost/,得到it works，说明apache已经配置成功了。  
7）停止Apache服务：  
\# /usr/local/apache2/bin/apachectl stop  
8）设置启动系统后，自启动Apache服务  
编辑etc/rc.d/rc.local  
\# vi /etc/rc.d/rc.local  
在最后加上一句： /usr/local/apache2/bin/apachectl start  
3、安装subversion  
1）解包  
\# tar xvzf subversion-1.4.5.tar.gz  
\# tar xvzf subversion-deps-1.4.5.tar.gz  
2）转入解包目录并生成配置文件  
\# cd subversion-1.4.5  
SVN 依赖的APR版本要正确。如果Apache为2.0.x，对应的APR版本应为0.9.x；Apache为2.2.x，对应的APR版本应为1.2.x。 由于subversion-deps包里的APR是0.9.x的，因此编译svn时要删除从deps里解压出来的apr, apr-util，改而使用apache 2.2里提供的。（这里指定为开始安装的apr目录）  
如果apache不是安装在默认路径，configure必須加上--with-apxs选项,如：./configure --with-apxs=/usr/local/apache2/bin/apxs(此目录为我的apache安装目录)  
\# rm -rf apr  
\# rm -rf apr-util  
#./configure --with-apxs=/usr/local/apache2/bin/apxs --prefix=/usr/local/subversion --with-apr=/usr/local/apr/bin/apr-1-config --with-apr-util=/usr/local/apr/bin/apu-1-config --with-ssl --with-zlib --enable-maintainer-mode  
3）编译安装  
\# make；make install  
4）查看subversion两个动态库有没有安装成功  
\# vi /usr/local/apache2/conf/httpd.conf  
看到下面两个模块说明安装成功  
LoadModule dav\_svn\_module modules/mod\_dav\_svn.so  
LoadModule authz\_svn\_module modules/mod\_authz\_svn.so  
5 ）配置apache 支持svn  
\# vi / usr/local/apache2/conf/httpd.conf  
在文件末尾加上  
&lt;Location /svn&gt;  
DAV svn  
SVNParentPath /subversion/project(此处配置你的版本库根目录)  
AuthType Basic  
AuthName "Subversion repository"（此处字符串内容修改为提示对话框标题）  
AuthUserFile /subversion/passwd (此处修改为访问版本库用户的文件，用apache 的 htpasswd命令生成)  
AuthzSVNAccessFile /subversion/auth （此处修改为访问版本库权限的文件）  
Require valid-user  
&lt;/Location&gt;  
6 ）建立版本库  
先创建版本根目录  
\# mkdir-p/subversion/project  
/usr/local/subversion/bin/svnadmin create /subversion/project/test  
更改版本库权限，这样通过apache服务访问svn的客户就有权限来编辑版本库文件  
Chown –R apache:apache /subversion/project/test  
进入到版本库 test中执行ls  
\# cd/subversion/project/test  
\# ls后看到以下文件夹及文件，则表示建库成功  
confdavdbformathookslocksREADME.txt  
测试用： 备份刚创建的SVN库  
\# /usr/local/subversion/bin/svnadmin dump / subversion/project/test &gt; /usr/local/svn-test  
把备份出来的数据恢复到库中  
\# /usr/local/subversion/bin/svnadmin load /subversion/project &lt; /usr/local/svn-test  
7 ) 建立访问库用户文件  
\# /usr/local/apache2/bin/htpasswd –cm /subversion/passwd dyf （第一次添加用户需先创建文件，所以有参数-c，以后添加用户可以不用添加参数）  
按照提示输入密码  
8 ）建立访问库权限文件  
\# vi /subversion/auth  
内容按照以下格式  
\[groups]  
Tester=test,dyf  
Developer=zb  
\[test:/]  
@Tester = rw  
dyf = rw  
zb = r  
9\) 浏览器+权限 访问版本库  
重起apache  
在浏览器中输入http://servername/svn/test  
输入拥有访问权限的用户名，密码登陆，  
4、安装php支持库 libxml2  
1）解包  
\# tar -zxf libxml2-2.6.19.tar.gz  
2）生成配置文件  
\# ./configure --prefix=/usr/local/libxml2  
3）编译并安装  
\# make；make install  
5、安装php5.2.5  
1）解包  
\# tar -zvxf php-5.2.5.tar.gz  
2）生成配置文件  
\# cd php-5.2.5  
\# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-libxml-dir=/usr/local/libxml --with-zlib --with-freetype-dir=/usr --enable-ftp  
3 ）编译并安装  
#make；make install  
4 ）添加php配置文件  
#cp php.ini-dist /usr/local/php/lib/php.ini  
5）配置Apache让其支持php：  
\# vi /usr/local/apache2/conf/httpd.conf  
找到 AddType application/x-gzip .gz .tgz 在其下添加如下内容  
AddType application/x-httpd-php .php .php3 .php4  
AddType application/x-httpd-php-source .phps  
找到DirectoryIndex index.html 修改成为 DirectoryIndex index.php index.html index.htm  
6） 用apache 支持php将svn中的所有版本库都显示出来  
在 /usr/local/apache2/htdocs目录下创建svn\_index.php,内容如下：  
&lt;html&gt;  
&lt;head&gt;  
&lt;title&gt;Subversion Repositories&lt;/title&gt;  
&lt;/head&gt;  
&lt;body&gt;  
&lt;h2&gt;Subversion Repositories&lt;/h2&gt;  
&lt;p&gt;  
&lt;?php $svnparentpath = "/subversion/project";  
$svnparenturl = "/svn";  
$dh = opendir( $svnparentpath );  
if( $dh ) {  
while( $dir = readdir( $dh ) ) {  
$svndir = $svnparentpath . "/" . $dir;  
$svndbdir = $svndir . "/db";  
$svnfstypefile = $svndbdir . "/fs-type";  
if( is\_dir( $svndir ) && is\_dir( $svndbdir ) ) {  
echo "&lt;a href=\\"" . $svnparenturl . "/" .  
$dir . "\\"&gt;" . $dir . "&lt;/a&gt;\\n";  
if( file\_exists( $svnfstypefile ) ) {  
$handle = fopen ("$svnfstypefile", "r");  
$buffer = fgets($handle, 4096);  
fclose( $handle );  
$buffer = chop( $buffer );  
if( strcmp( $buffer, "fsfs" )==0 ) {  
echo " (FSFS) &lt;br /&gt;\\n"; } else {echo " (BDB) &lt;br /&gt;\\n"; }  
} else {  
echo " (BDB) &lt;br /&gt;\\n";  
}  
}  
} closedir( $dh ); }  
?&gt;  
&lt;/p&gt;  
&lt;/body&gt;  
&lt;/html&gt;  
上述php文件中svnparentpath = "/subversion/project";需要注意，这块儿配置你的subversion的代码仓库的根目录即可，请修改和你自己设置一样的路径。更 改Apache的配置文件httpd.conf文件，在文件末尾加上如下几句：  
RewriteEngine on  
RewriteRule ^/svn$ /svn\_index.php \[PT]  
RewriteRule ^/svn/$ /svn\_index.php \[PT]  
RewriteRule ^/svn/index.html$ /svn\_index.php \[PT]  
重新启动apache好了，请从新在浏览器地址栏中输入http://youserver/svn ，你会发现Apache会把当前Subversion根目录下的所有代码仓库列出来了。