How to Configure LDAP Authentication for Subversion on CentOS 5.5

In this post, i will show you on how to configure your existing subversion with LDAP authentication. This guideline assume that you are already configure the Apache and subversion with htpasswd user. 389 LDAP has been installed but not yet configure in your subversion configuration file.

Prerequisite :
a)How to Install Apache Httpd Web Server on Linux
b)How to Install Subversion 1.6.16 on CentOS 5.5 Server
c)How to Install 389 Directory Server on CentOS/RHEL

Steps:
1. Locate and open subversion.conf using vi editor

    [root@server ~]# vi /etc/httpd/conf.d/subversion.conf
    

2. Modify the existing subversion.conf to below:

    # Needed to do Subversion Apache server.
    LoadModule dav_svn_module     modules/mod_dav_svn.so
    
    # Only needed if you decide to do "per-directory" access control.
    LoadModule authz_svn_module   modules/mod_authz_svn.so
    
    #
    # Example location directive.
    #
    
    <Location /svn/repos>
            DAV svn
            SVNParentPath /svn/repos
            AuthBasicProvider ldap
            AuthType Basic
            AuthzLDAPAuthoritative on
            AuthName "My Subversion server"
            AuthLDAPURL "ldap://ldap.intranet.local:389/DC=intranet,DC=local?uid?sub?(objectClass=*)" NONE
            AuthzSVNAccessFile /svn/permissions/svnaccess
            Require valid-user
    </Location>
    

3. Save configuration file and restart the apache server.

    [root@server ~]# service httpd restart
    Stopping httpd:                                            [  OK  ]
    Starting httpd:                                            [  OK  ]
    

How to Install and Configure ViewVC for Subversion on CentOS

Another alternative for subversion repositories web viewer is ViewVC. Just like WebSVN, viewvc having many useful features such as viewing subversion repositories, directories, to view change log listings and it can display specific versions of files as well as diffs between those versions. At the time of this post wrote, the most recent stable release of ViewVC is release 1.1.10.

Prerequisite :
1. How to Install Apache Httpd Web Server on Linux
2. How to Install Subversion on CentOS 5.5 Server

Steps to Install and Configure ViewVC.
1. Download ViewVC stable release 1.1.10
You can download using wget command on CentOS server as below:

    wget http://viewvc.tigris.org/files/documents/3330/48879/viewvc-1.1.10.tar.gz
    
    [root@server ~]# cd /tmp
    [root@server tmp]# wget http://viewvc.tigris.org/files/documents/3330/48879/viewvc-1.1.10.tar.gz
    --2011-04-03 19:09:06--  http://viewvc.tigris.org/files/documents/3330/48879/viewvc-1.1.10.tar.gz
    Resolving viewvc.tigris.org... 204.16.104.146
    Connecting to viewvc.tigris.org|204.16.104.146|:80... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 602017 (588K) [application/x-gzip]
    Saving to: `viewvc-1.1.10.tar.gz'
    
    100%[===========================================>] 602,017     20.0K/s   in 29s
    
    2011-04-03 19:09:38 (20.3 KB/s) - `viewvc-1.1.10.tar.gz' saved [602017/602017]
    

2. Extract and unzip the viewvc-1.1.10.tar.gz using below command:

    [root@server tmp]# tar xvfz viewvc-1.1.10.tar.gz
    

3. Go to viewvc-1.1.10 directory and start the installation:

    ./viewvc-install
    
    [root@server tmp]# cd viewvc-1.1.10
    [root@server viewvc-1.1.10]# ./viewvc-install
    This is the ViewVC 1.1.10 installer.
    
    It will allow you to choose the install path for ViewVC.  You will now
    be asked some installation questions.  Defaults are given in square brackets.
    Just hit [Enter] if a default is okay.
    
    Installation path [/usr/local/viewvc-1.1.10]:
    
    DESTDIR path (generally only used by package maintainers) []:
    -
    -
    -
    -
    -
    -
    -
    ViewVC file installation complete.
    
    Consult the INSTALL document for detailed information on completing the
    installation and configuration of ViewVC on your system.  Here's a brief
    overview of the remaining steps:
    
      1) Edit the /usr/local/viewvc-1.1.10/viewvc.conf file.
    
      2) Either configure an existing web server to run
         /usr/local/viewvc-1.1.10/bin/cgi/viewvc.cgi.
    
         Or, copy /usr/local/viewvc-1.1.10/bin/cgi/viewvc.cgi to an
         already-configured cgi-bin directory.
    
         Or, use the standalone server provided by this distribution at
         /usr/local/viewvc-1.1.10/bin/standalone.py.
    

3. Edit /viewvc.conf for your specific
configuration. In particular, examine the following configuration options:

          svn_roots (for Subversion)
          root_parents (for CVS or Subversion)
          default_root
          root_as_url_component
          rcs_dir
          mime_types_files
    
    [root@server ~]# vi /usr/local/viewvc-1.1.10/viewvc.conf
    
        147 ## Example:
        148 ## root_parents = /opt/svn: svn,
        149 ##                /opt/cvs: cvs
        150 ##
        151 root_parents =
        152
    

Uncomment line 151 and define the subversion root repositories.

    root_parents = /svn/repos: svn,
    

4. Locate your Apache configuration file. Typical locations are:

    /etc/httpd/httpd.conf,
    /etc/httpd/conf/httpd.conf, and
    /etc/apache/httpd.conf.
    

Depending on how Apache was installed. Configure Apache to expose ViewVC to users at the URL of your choice. Edit the apache web server config file as below:

    [root@server ~]# vi /etc/httpd/conf/httpd.conf
    
    565 ScriptAlias /viewvc /usr/local/viewvc-1.1.10/bin/cgi/viewvc.cgi
    566 ScriptAlias /query /usr/local/viewvc-1.1.10/bin/cgi/query.cgi
    

or if without line number, it will be as below:

    ScriptAlias /viewvc /usr/local/viewvc-1.1.10/bin/cgi/viewvc.cgi
    ScriptAlias /query /usr/local/viewvc-1.1.10/bin/cgi/query.cgi
    
    # ScriptAlias: This controls which directories contain server scripts.
    # ScriptAliases are essentially the same as Aliases, except that
    # documents in the realname directory are treated as applications and
    # run by the server when requested rather than as documents sent to the client.
    # The same rules about trailing "/" apply to ScriptAlias directives as to
    # Alias.
    #
    ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
    ScriptAlias /viewvc /usr/local/viewvc-1.1.10/bin/cgi/viewvc.cgi
    ScriptAlias /query /usr/local/viewvc-1.1.10/bin/cgi/query.cgi
    #
    # "/var/www/cgi-bin" should be changed to whatever your ScriptAliased
    # CGI directory exists, if you have that configured.
    

5. Save the httpd.conf then restart the apache server.
6. Test your http://servername/viewvc. If everything properly configured, you should see the page that lists your repositories.

How to Install WebSVN for Subversion on CentOS

In this post, i will guide you on how to set up the WebSVN in your subversion repository. WebSVN will enable you to view your subversion repositories with default useful features as below:-

  • Blame (annotation) view of file authorship
  • Comparing revisions of files / directories
  • Revision and log message browsing / searching
  • RSS feed support for watching any resource

In order to enable other features such as path-based restriction of privileges, proper customization of config.php code is needed. At the time of this article wrote, the current release of WebSVN is WebSVN Release 2.3.2.

Prerequisite :
1. How to Install Apache Httpd Web Server on Linux
2. How to Install Subversion on CentOS 5.5 Server

Steps to install WebSVN :
1. Download the WebSVN Release 2.3.2
You can wget as below. Make sure that you put it or move it to your repository directory.

    [root@server repos]# pwd
    /svn/repos
    [root@server repos]# http://websvn.tigris.org/files/documents/1380/48737/websvn-2.3.2.tar.gz
    -bash: http://websvn.tigris.org/files/documents/1380/48737/websvn-2.3.2.tar.gz: No such file or directory
    [root@server repos]# clear
    [root@server repos]# pwd
    /svn/repos
    [root@server repos]# wget http://websvn.tigris.org/files/documents/1380/48737/websvn-2.3.2.tar.gz
    --2011-04-03 17:53:20--  http://websvn.tigris.org/files/documents/1380/48737/websvn-2.3.2.tar.gz
    Resolving websvn.tigris.org... 204.16.104.146
    Connecting to websvn.tigris.org|204.16.104.146|:80... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 846511 (827K) [application/x-gzip]
    Saving to: `websvn-2.3.2.tar.gz'
    
    100%[===========================================>] 846,511     72.9K/s   in 31s
    
    2011-04-03 17:53:53 (26.5 KB/s) - `websvn-2.3.2.tar.gz' saved [846511/846511]
    

2. Extract and unzip the websvn-2.3.2.tar.gz using below command and rename it as websvn for easy browsing URL as below:
http://servername/websvn/

    [root@server repos]# tar xvfz websvn-2.3.2.tar.gz
    [root@server repos]# mv websvn-2.3.2 websvn
    

3. Go to websvn/include directory. Make a copy of distconfig.php and name it as config.php. config.php will be the main configuration file of your WebSVN.

    [root@server repos]# cd websvn/include
    [root@server include]# ls
    accessfile.php  command.php      diff_util.php   setup.php     utils.php
    auth.php        configclass.php  distconfig.php  svnlook.php   version.php
    bugtraq.php     diff_inc.php     header          template.php
    [root@server include]# cp distconfig.php config.php
    

4. Edit the config.php file. Then uncomment line 106 and modify the parentPath as below:

    [root@server include]# vi config.php
    106 // $config->parentPath('Path/to/parent (e.g. c:\\svn)');
    

Change to :

    106 $config->parentPath('/svn/repos');
    

5. Save the config.php then test your http://servername/websvn. If everything properly configured, you should see the page that lists your repositories.

How to Install Subversion 1.6.16 on CentOS 5.5 Server

Subversion is a open source version control system that will manages files and will keep the changes made to the files, over time. This will allows us to recover older versions of the data or examine the history of how the data changed. In this post, i will show you on how to install Subversion 1.6.16 on CentOS 5.5.

Prerequisite : How to Install Apache Httpd Web Server on Linux

1. Download Subversion 1.6.16

    [root@server data]# wget http://opensource.wandisco.com/centos/5/RPMS/i386/mod_dav_svn-1.6.16-1.i386.rpm
    --2011-03-29 20:20:22--  http://opensource.wandisco.com/centos/5/RPMS/i386/mod_dav_svn-1.6.16-1.i386.rpm
    Resolving opensource.wandisco.com... 212.7.198.163
    Connecting to opensource.wandisco.com|212.7.198.163|:80... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 77152 (75K) [application/x-redhat-package-manager]
    Saving to: `mod_dav_svn-1.6.16-1.i386.rpm'
    
    100%[===========================================>] 77,152      47.1K/s   in 1.6s
    
    2011-03-29 20:20:25 (47.1 KB/s) - `mod_dav_svn-1.6.16-1.i386.rpm' saved [77152/77152]
    
    [root@server data]# wget http://opensource.wandisco.com/centos/5/RPMS/i386/subversion-1.6.16-1.i386.rpm
    --2011-03-29 20:22:31--  http://opensource.wandisco.com/centos/5/RPMS/i386/subversion-1.6.16-1.i386.rpm
    Resolving opensource.wandisco.com... 212.7.198.163
    Connecting to opensource.wandisco.com|212.7.198.163|:80... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 2191952 (2.1M) [application/x-redhat-package-manager]
    Saving to: `subversion-1.6.16-1.i386.rpm'
    
    100%[===========================================>] 2,191,952   53.4K/s   in 51s
    
    2011-03-29 20:23:25 (41.9 KB/s) - `subversion-1.6.16-1.i386.rpm' saved [2191952/2191952]
    
    [root@server data]# wget http://opensource.wandisco.com/centos/5/RPMS/i386/subversion-devel-1.6.16-1.i386.rpm
    --2011-03-29 20:26:47--  http://opensource.wandisco.com/centos/5/RPMS/i386/subversion-devel-1.6.16-1.i386.rpm
    Resolving opensource.wandisco.com... 212.7.198.163
    Connecting to opensource.wandisco.com|212.7.198.163|:80... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 3407709 (3.2M) [application/x-redhat-package-manager]
    Saving to: `subversion-devel-1.6.16-1.i386.rpm'
    
    100%[===========================================>] 3,407,709   53.6K/s   in 62s
    
    2011-03-29 20:27:51 (53.9 KB/s) - `subversion-devel-1.6.16-1.i386.rpm' saved [3407709/3407709]
    
    [root@server data]# wget http://opensource.wandisco.com/centos/5/RPMS/i386/subversion-perl-1.6.16-1.i386.rpm
    --2011-03-29 20:28:05--  http://opensource.wandisco.com/centos/5/RPMS/i386/subversion-perl-1.6.16-1.i386.rpm
    Resolving opensource.wandisco.com... 212.7.198.163
    Connecting to opensource.wandisco.com|212.7.198.163|:80... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 1103833 (1.1M) [application/x-redhat-package-manager]
    Saving to: `subversion-perl-1.6.16-1.i386.rpm'
    
    100%[===========================================>] 1,103,833   66.8K/s   in 21s
    
    2011-03-29 20:28:28 (52.3 KB/s) - `subversion-perl-1.6.16-1.i386.rpm' saved [1103833/1103833]
    
    [root@server data]# wget http://opensource.wandisco.com/centos/5/RPMS/i386/subversion-python-1.6.16-1.i386.rpm
    --2011-03-29 20:28:36--  http://opensource.wandisco.com/centos/5/RPMS/i386/subversion-python-1.6.16-1.i386.rpm
    Resolving opensource.wandisco.com... 212.7.198.163
    Connecting to opensource.wandisco.com|212.7.198.163|:80... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 1286789 (1.2M) [application/x-redhat-package-manager]
    Saving to: `subversion-python-1.6.16-1.i386.rpm'
    
    100%[===========================================>] 1,286,789   30.2K/s   in 42s
    
    2011-03-29 20:29:20 (30.1 KB/s) - `subversion-python-1.6.16-1.i386.rpm' saved [1286789/1286789]
    
    [root@server data]# wget http://opensource.wandisco.com/centos/5/RPMS/i386/subversion-tools-1.6.16-1.i386.rpm
    --2011-03-29 20:30:09--  http://opensource.wandisco.com/centos/5/RPMS/i386/subversion-tools-1.6.16-1.i386.rpm
    Resolving opensource.wandisco.com... 212.7.198.163
    Connecting to opensource.wandisco.com|212.7.198.163|:80... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 390211 (381K) [application/x-redhat-package-manager]
    Saving to: `subversion-tools-1.6.16-1.i386.rpm'
    
    100%[===========================================>] 390,211     54.9K/s   in 7.2s
    
    2011-03-29 20:30:19 (53.1 KB/s) - `subversion-tools-1.6.16-1.i386.rpm' saved [390211/390211]
    
    [root@server data]# ls
    mod_dav_svn-1.6.16-1.i386.rpm       subversion-perl-1.6.16-1.i386.rpm
    subversion-1.6.16-1.i386.rpm        subversion-python-1.6.16-1.i386.rpm
    subversion-devel-1.6.16-1.i386.rpm  subversion-tools-1.6.16-1.i386.rpm

2. Install the RPM packages

    [root@server data]# rpm -Uvh --nosignature mod_dav_svn-1.6.16-1.i386.rpm subversion-1.6.16-1.i386.rpm subversion-devel-1.6.16-1.i386.rpm subversion-perl-1.6.16-1.i386.rpm subversion-python-1.6.16-1.i386.rpm subversion-tools-1.6.16-1.i386.rpm
    Preparing...                ########################################### [100%]
    1:subversion             ########################################### [ 17%]
    2:subversion-perl        ########################################### [ 33%]
    3:mod_dav_svn            ########################################### [ 50%]
    4:subversion-devel       ########################################### [ 67%]
    5:subversion-python      ########################################### [ 83%]
    6:subversion-tools       ########################################### [100%]
    [root@server data]#

3. Setting up directories

    mkdir /svn
    mkdir /svn/repos
    mkdir /svn/users
    mkdir /svn/permissions
    
    chown -R apache:apache /svn

4. Configure httpd Apache server as below:

    DocumentRoot /svn/repos
    ServerName svn.local
    ErrorLog logs/svn.local-error_log
    CustomLog logs/svn.local-access_log common

5. Create and Configure subversion.conf

[root@server ~]# vi /etc/httpd/conf.d/subversion.conf

     
    # Needed to do Subversion Apache server.
    LoadModule dav_svn_module     modules/mod_dav_svn.so
    
    # Only needed if you decide to do "per-directory" access control.
    LoadModule authz_svn_module   modules/mod_authz_svn.so
    
    #
    # Example location directive.
    #
    
    <Location /svn/repos>
            DAV svn
            SVNParentPath /svn/repos
            AuthType Basic
    	AuthName "Authorization Realm"
    	AuthUserFile /svn/users/passwords
            AuthzSVNAccessFile /svn/permissions/svnaccess
            Require valid-user
    </Location>
    
    

6. Create first repository using svnadmin command

    [root@server ~]# svnadmin create /svn/repos/testsvn
    [root@server ~]# chown -R apache:apache /svn/repos/testsvn

7. Create htpasswd user to access the testsvn repository

    [root@server ~]# htpasswd -c /svn/users/passwords user1
    New password:
    Re-type new password:
    Adding password for user user1
    
    [root@server ~]# htpasswd -m /svn/users/passwords user2
    New password:
    Re-type new password:
    Adding password for user user2

8. Create svnaccess file to access the testsvn repository

    [root@server ~]# vi /svn/permissions/svnaccess
    [groups]
    testgroup = user1, user2
    
    [testsvn:/]
    @testgroup = rw

9. Test your subversion server from browser http://192.168.2.5/svn/repos/testsvn/

    testsvn - Revision 0: /
    
    --------------------------------------------------------------------------------
    Powered by Subversion version 1.6.16 (r1073529).

Proceed to below URL if you want to view your repository using WebSVN or Viewvc.
How to Install WebSVN on CentOS
How to Install and Configure Viewvc on CentOS