Wednesday, December 17, 2008

Subversion with apache on Centos

I used Centos4 as OS on which I installed subversion with apache. It was painful three days but it was sucess at the end. Before we start with this I have to say couple of important things:
subversion 1.4.x will work with apache-2.0.x cause they relay on APR 0.9.x module, and
subversion-1.5.x will work with apache-2.2.x cause they relay on APR 1.3.x module.
APR 0.9.x and APR 1.3.x are not compatibile, and because of that, subversion 1.5.x will not work with apache-2.0.x. Same case is probably with subversion 1.4.x and apache-2.2.x combination. When installing subversion modules for apache from source you'll need to tell to configuration where are APR and APR-UTIL libraries. You can use these libraries from apache source or from subversion. I decided to use APR and APR-UTIL libraries from apache source.

Subversion uses a lot of other programs and libraries which need to be installed before using the subversion package. So to simplify things I'll try using yum as much as possible.

Update your version of apache and install subversion that fits this version of apache using yum:
yum upgrade httpd

Add repos to yum:
joe /etc/yum.repos.d/dag.repo

[dag]
Name=Dag RPM Repository for Red Hat Enterprise Linux
baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag
gpgkey=http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt
gpgcheck=1
enabled=1

Then install these packages:
yum install httpd-devel
yum install subversion

Check the version of your installed apache (2.0.52 in my case) using:
yum info httpd

and download apropriate source using:
wget http://apache.blic.net/httpd/httpd-2.0.63.tar.gz

There is no source for 2.0.52 any more so I used 2.0.63 with crossed fingers.
tar xfz httpd-2.0.63.tar.gz
cd httpd-2.0.63

cd apr
./configure --prefix=/usr/local/apr
make
make install
cd ..

cd apr-util
./configure --prefix=/usr/local/apr-utils --with-apr=/usr/local/apr/
make
make install
cd ..

Check the version of your installed subversion (1.4.6 in my case) using:
yum info subversion

and download apropriate source using:
wget http://subversion.tigris.org/downloads/subversion-deps-1.4.6.tar.gz
wget http://subversion.tigris.org/downloads/subversion-1.4.6.tar.gz

tar xfz subversion-1.4.6.tar.gz
tar xfz subversion-deps-1.4.6.tar.gz
cd subversion-1.4.6

rm -f /usr/local/lib/libsvn*
rm -f /usr/local/lib/libapr*
rm -f /usr/local/lib/libexpat*
rm -f /usr/local/lib/libneon*
sh ./autogen.sh

./configure --with-apxs=/usr/sbin/apxs \
--with-apr=/usr/local/apr/ \
--with-apr-util=/usr/local/apr-utils/
make
make install

At this point you will have included two svn modules in httpd.conf file which is why we did compiling from source.

Make your project for first revision of repository
mkdir -v /usr/local/svn-projects
mkdir -v /usr/local/svn-projects/htdocs
joe /usr/local/svn-projects/htdocs/index.html
chown -Rv apache.apache /usr/local/svn-projects

Make your repository
mkdir -v /usr/local/subversion/
/usr/local/bin/svnadmin create --fs-type fsfs /usr/local/subversion/repository
chown -Rv apache.apache /usr/local/subversion
ls /usr/local/subversion/repository

Edit httpd.conf.
Check that there are two loaded svn modules.
LoadModule dav_svn_module /usr/lib/httpd/modules/mod_dav_svn.so
LoadModule authz_svn_module /usr/lib/httpd/modules/mod_authz_svn.so

Add this code to apache httpd.conf:
< Location /subversion>
DAV svn
SVNPath /usr/local/subversion/repository/
AuthType Basic
AuthName "Subversion repository"
AuthUserFile /usr/local/subversion/repository/conf/svn-auth-file
Require valid-user
</Location>

Add new users. For first user:
htpasswd -cmd /usr/local/subversion/repository/conf/svn-auth-file {user-name}

For every other user:
htpasswd -md /usr/local/subversion/repository/conf/svn-auth-file {user-name}

Prepare files for repository and import your project to repository:
mkdir -pv /tmp/subversion-layout/{branches,tags}
mv -v /usr/local/svn-projects/htdocs /tmp/subversion-layout/trunk
export SVN_EDITOR=joe
/usr/local/bin/svn import /tmp/subversion-layout/ http://127.0.0.1/subversion/

Make your working copy:
cd /usr/local/svn-projects/
/usr/local/bin/svn checkout http://127.0.0.1/subversion/trunk/ htdocs

Make post-commit hook to get fresh working copy:
cp -v /usr/local/subversion/repository/hooks/post-commit.tmpl /usr/local/subversion/repository/hooks/post-commit
chmod +x /usr/local/subversion/repository/hooks/post-commit

Edit post-commit hook by commenting two last lines and by adding one line like this:
#commit-email.pl "$REPOS" "$REV" commit-watchers@example.org
#log-commit.py --repository "$REPOS" --revision "$REV"
/usr/bin/svn update /usr/local/svn-projects/htdocs/ --username svn_user --password svn_pass --non-interactive >> /usr/local/subversion/repository/logs/post-commit.log

Make log file for created hook:
mkdir -v /usr/local/subversion/repository/logs/
touch /usr/local/subversion/repository/logs/post-commit.log
chown -Rv apache.apache /usr/local/subversion/ /usr/local/svn-projects/

Restart your apache and you'll have your first revision working:
/bin/sbin/httpd -k restart

Cheers!

No comments: