Apache Subversion (SVN)

Subversion (SVN) is an open-source version control system (VCS) that emerged to replace the limited CVS. SVN manages files and directories and the changes made to them over time. This allows us to retrieve old versions of your data or examine the change history.

Although I’m not a big fan of Subversion (Git FTW!), I also don’t hate it like Linus and have needed to use it for a college project.

  1. Perform the initial installations and configurations

    1. Install Subversion

      julio@julio-acer ~> sudo pacman -S subversion
    2. Install Apache

      julio@julio-acer ~> sudo pacman -S apache

      Tips for configuring Apache are available in the Wiki.

    3. Check if the following lines are present in the

      /etc/httpd/conf/httpd.conf e adicione as que não estiverem:
          LoadModule dav_module           modules/mod_dav.so
          LoadModule dav_fs_module        modules/mod_dav_fs.so
          LoadModule dav_svn_module       modules/mod_dav_svn.so
          LoadModule authz_svn_module     modules/mod_authz_svn.so
    4. Make sure the line Include /etc/httpd/conf/extra/httpd-ssl.conf is uncommented in /etc/httpd/conf/httpd.conf

    5. Generate an SSL certificate

      [root@julio-acer ~]# cd /etc/httpd/conf/
      [root@julio-acer conf]# openssl req -new -x509 -keyout server.key -out server.crt -days 365 -nodes
      Generating a 1024 bit RSA private key
      writing new private key to 'server.key'
      You are about to be asked to enter information that will be incorporated
      into your certificate request.
      What you are about to enter is what is called a Distinguished Name or a DN.
      There are quite a few fields but you can leave some blank
      For some fields there will be a default value,
      If you enter '.', the field will be left blank.
      Country Name (2 letter code) [AU]:BR
      State or Province Name (full name) [Some-State]:Sao Paulo
      Locality Name (eg, city) []:Sao Jose dos Campos
      Organization Name (eg, company) [Internet Widgits Pty Ltd]:
      Organizational Unit Name (eg, section) []:
      Common Name (eg, YOUR name) []:Julio
      Email Address []:julio@…
    6. Add the following lines to the file

      `/etc/httpd/conf/extra/httpd-ssl.conf` para fazer o Apache suportar SVN
          ## Para o SVN
          <Location /svn>
              DAV svn
              SVNParentPath /srv/svn/repositorios
              AuthName "SVN Repositories"
              AuthType Basic
              AuthzSVNAccessFile /srv/svn/svn-policy
              AuthUserFile /srv/svn/svn-auth
              Satisfy Any
              Require valid-user
  2. Configure directories, users, and permissions

    1. Create a group for ssh access to the repositories

      [root@julio-acer ~]# groupadd svnusers
    2. Create a directory where all repositories will be maintained

      julio@julio-acer ~> mkdir -p /srv/svn/repositorios
      julio@julio-acer ~> chmod -R 755 /srv/svn/repositorios

      This directory can be created in another location. Here I left it in /srv/svn because it is the directory I used when I installed rTorrent from SVN, as described in this Post.

    3. Ensure you and Apache have access to the repositories

    julio@julio-acer ~> sudo gpasswd -a http svnusers
    Adding user http to group svnusers
    julio@julio-acer ~> sudo gpasswd -a julio svnusers
    Adding user julio to group svnusers

    Logout to take effect.

  3. Create the file /srv/svn/svn-policy and make it similar to the following

    julio@julio-acer ~> cat /srv/svn/svn-policy
    * = r
    julio = rw
  4. Create the file /srv/svn/svn-auth with htpasswd or htdigest

    [root@julio-acer ~]# htpasswd -cs /srv/svn/svn-auth julio
    New password:
    Re-type new password:
    Adding password for user julio

    To add other users, just remove the -c from the command.

  5. Create a repository

    julio@julio-acer ~> svnadmin create /srv/svn/repositorios/projeto
    1. Change permissions

      julio@julio-acer ~> sudo chown -R http.svnusers /srv/svn/repositorios/projeto
      julio@julio-acer ~> sudo chmod -R g-w /srv/svn/repositorios/projeto
      julio@julio-acer ~> sudo chmod -R g+w /srv/svn/repositorios/projeto/{db,locks}
  6. Repository structure

    The typical structure of a repository looks like the following:

    • Branches: Stores copies of files being developed or maintained, but on a separate development line. For example, the code for v4 may be within a Branch to allow people to work on future changes that will not be implemented soon. This allows them to do their work without prematurely putting code into the trunk.

    • Tags: Stores copies of the software at various stages of development, such as v1, v2, and v3.

    • Trunk: - Used to maintain the most up-to-date stable version of the software.

  7. Putting a project under version control Assuming we already have a project called codefest, let’s import its files into the trunk folder of the “projeto” repository:

    julio@julio-acer ~> svn import ~/codefest/ file:///srv/svn/repositorios/projeto/trunk -m 'importacao inicial'
    Adding         /home/julio/codefest/amostras
    Adding  (bin)  /home/julio/codefest/amostras/codefest.xls
    Adding         /home/julio/codefest/amostras/imagens
    Adding  (bin)  /home/julio/codefest/amostras/imagens/1.jpg
    Adding  (bin)  /home/julio/codefest/amostras/imagens/2.jpg
    Adding  (bin)  /home/julio/codefest/amostras/imagens/3.jpg
    Adding         /home/julio/codefest/amostras/codefest.txt
    Adding         /home/julio/codefest/código
    Adding         /home/julio/codefest/código/matching.py
    Adding         /home/julio/codefest/código/color_name.py
    Adding         /home/julio/codefest/código/inicializador.py
    Adding         /home/julio/codefest/código/image.py
    Adding         /home/julio/codefest/código/dominant_color.py
    Committed revision 1.

    To list the trunk directory after the commit, just use the following command

    julio@julio-acer ~> svn ls file:///srv/svn/repositorios/projeto/trunk
  8. Checkout

    julio@julio-acer ~> svn co file:///srv/svn/repositorios/projeto/trunk ~/codefest-svn
    A    /home/julio/codefest-svn/amostras
    A    /home/julio/codefest-svn/amostras/codefest.xls
    A    /home/julio/codefest-svn/amostras/imagens
    A    /home/julio/codefest-svn/amostras/imagens/1.jpg
    A    /home/julio/codefest-svn/amostras/imagens/2.jpg
    A    /home/julio/codefest-svn/amostras/imagens/3.jpg
    A    /home/julio/codefest-svn/amostras/codefest.txt
    A    /home/julio/codefest-svn/código
    A    /home/julio/codefest-svn/código/matching.py
    A    /home/julio/codefest-svn/código/color_name.py
    A    /home/julio/codefest-svn/código/inicializador.py
    A    /home/julio/codefest-svn/código/image.py
    A    /home/julio/codefest-svn/código/dominant_color.py
    Checked out revision 1.
  9. Protocols

    • file:// → Basic, but you can only work on the same machine hosting the repositories.
    • svn:// → Uses a server to communicate with Subversion (Apache in this case).
    • svn+ssh:// → Uses SSH to communicate with the server
    • http:// → Friendly, uses WEBDAV to allow communication via HTTP with Subversion repositories.
    • https:// → Like http, but with SSL encryption
  10. Restart Apache

    julio@julio-acer ~> sudo /etc/rc.d/httpd restart
    :: Restarting Apache Web Server                             [DONE]

    Now you should be able to navigate through the project by accessing https://localhost/svn/projeto/.

Julio Batista Silva
Julio Batista Silva
Data Engineer

I’m a computer engineer passionate about science, technology, photography, and languages. Currently working as a Data Engineer in Germany.

comments powered by Disqus