Setting Up Subversion And Trac As Virtual Hosts On An Ubuntu Server 

This howto outlines the process by which one can set up the Subversion version control system, and have it work in tandem with Trac, the project manager for software development projects, on a server running Ubuntu (or possibly Debian). It is brought to you by Openject Consulting.

 

Setting up Subversion

For detailed information on this, including alternate setups, have a look at Version Control with Subversion.

  1. Install the required packages.
    sudo aptitude install enscript libapache2-mod-python python-docutils trac db4.3-util libapache2-svn subversion-tools
  2. Create a virtual host directory for SVN. We'll use /var/local/svn instead of /var/www so that Subversion instances don't clog up the directory of web root directories.
    sudo mkdir -p /var/local/svn/svn.example.com
  3. Create a development group, and add the web user to it.
    sudo addgroup example; sudo adduser www-data example
  4. Add users to the development group. These are persons that need access to the repository.
    sudo adduser username1 example
    sudo adduser username2 example
    sudo adduser username3 example
  5. Set the proper permissions.
    sudo chmod 2770 /var/local/svn/svn.example.com
  6. Set up the repository.
    sudo svnadmin create /var/local/svn/svn.example.com
  7. Clear the current password file. By default it's for the svnserve protocol, but we'll be using HTTPS (or just HTTP). We'll be adding users to this file later in the process.
    sudo rm /var/local/svn/svn.example.com/conf/passwd
    sudo touch /var/local/svn/svn.example.com/conf/passwd
  8. Allow the group to write to the repository.
    sudo chmod -R g+w /var/local/svn/svn.example.com
  9. Set proper file ownership.
    sudo chown -R www-data:example /var/local/svn/svn.example.com
  10. Set the repository access permissions. Information on how to do this can be found in the Path-Based Authorization section of Version Control with Subversion.
    sudo vi /var/local/svn/svn.example.com/conf/authz
  11. Create a directory for the log files.
    sudo mkdir /var/log/apache2/svn.example.com
  12. Add the site to the log rotation list.
    sudo vi /etc/logrotate.d/apache2
  13. Configure the virtual host...
    sudo vi /etc/apache2/sites-available/svn.example.com
    ...with the following data. If you don't care about SSL, you can ignore the SSL options and run this on port 80.
    <VirtualHost [server's IP address]:443>
      ServerName svn.example.com
      <Location />
        DAV svn
        AuthType Basic
        AuthName "svn.example.com"
        AuthUserFile /var/local/svn/svn.example.com/conf/passwd
        AuthzSVNAccessFile /var/local/svn/svn.example.com/conf/authz
        SVNPath /var/local/svn/svn.example.com
        Require valid-user
      </Location>
      CustomLog /var/log/apache2/svn.example.com/access.log combined
      ErrorLog /var/log/apache2/svn.example.com/error.log
      SSLEngine on
      SSLCertificateFile /etc/apache2/ssl/apache.pem
    # Add this once there is a real (non self-signed) certificate.
    #  SSLCertificateKeyFile /etc/apache2/ssl/server.key
    </VirtualHost>
    <VirtualHost [server's IP address]:80>
      ServerName svn.example.com
      Redirect / https://svn.example.com/
    </VirtualHost>
    
    Reference:
    /etc/apache2/mods-enabled/dav_svn.conf
  14. Enable the subversion virtual host.
    sudo a2ensite svn.example.com
  15. Create user/password combinations.
    htpasswd /var/local/svn/svn.example.com/conf/passwd username
  16. Restart the web server.
    sudo /etc/init.d/apache2 restart
  17. If you're going to have users working locally, set up svnwrap. (See the man page for details.)
    sudo ln -s /usr/bin/svnwrap /usr/local/bin/svn

 

Setting up Trac

  1. Create the web directory. We'll use /var/local/trac instead of /var/www so as not to clog up the directory of webroots.
    sudo mkdir -p /var/local/trac/trac.example.com
  2. Set the proper permissions.
    sudo chmod 2770 /var/local/trac/trac.example.com
  3. Create a Trac instance.
    sudo trac-admin /var/local/trac/trac.example.com initenv
  4. Set proper ownership on the web directory.
    sudo chown -R www-data:example /var/local/trac/trac.example.com
  5. Allow the group to write to the repository.
    sudo chmod -R g+w /var/local/trac/trac.example.com
  6. Configure it.
    sudo vi /var/local/trac/trac.example.com/conf/trac.ini
  7. Create a directory for the log files.
    sudo mkdir /var/log/apache2/trac.example.com
  8. Add the site to the log rotation list.
    sudo vi /etc/logrotate.d/apache2
  9. Configure the virtual host...
    sudo vi /etc/apache2/sites-available/trac.example.com
    ...with the following data. If you don't care about SSL, you can skip the SSL options and run this on port 80.
    # Trac Configuration
    <VirtualHost [server's IP address]:80>
      ServerName trac.example.com
      Redirect / https://trac.example.com/
    </VirtualHost>
    <VirtualHost [server's IP address]:443>
      ServerName trac.example.com
      DocumentRoot /var/local/trac/trac.example.com/
      Alias /trac/ /usr/share/trac/htdocs
      <Directory "/usr/share/trac/htdocs/">
          Options Indexes MultiViews
          AllowOverride None
          Order allow,deny
          Allow from all
      </Directory>
      <Location />
          SetHandler mod_python
          PythonHandler trac.web.modpython_frontend
          PythonInterpreter main_interpreter
          PythonOption TracEnv /var/local/trac/trac.example.com/
          PythonOption TracUriRoot /
          AuthType Basic
          AuthName "trac.example.com"
          # Use the SVN password file.
          AuthUserFile /var/local/svn/svn.example.com/conf/passwd
          Require valid-user
      </Location>
      CustomLog /var/log/apache2/trac.example.com/access.log combined
      ErrorLog /var/log/apache2/trac.example.com/error.log
      SSLEngine on
      SSLCertificateFile /etc/apache2/ssl/apache.pem
    # Add this once there is a real (non self-signed) certificate.
    #  SSLCertificateKeyFile /etc/apache2/ssl/server.key
    </VirtualHost>
    
    Reference:
    http://trac.edgewall.org/wiki/TracOnUbuntu
  10. Enable the Trac virtual host.
    sudo a2ensite trac.example.com
  11. Configure Trac permissions. Once you're inside the administration console, execute the command "help permission" for information on how to do this. This is important because some settings are permissive by default, when they should be restrictive. Also, see the wiki page TracPermissions that comes with your new installation.
    trac-admin /var/local/trac/trac.example.com
  12. Restart the web server.
    sudo /etc/init.d/apache2 restart

The last thing to do is add the subdomains "svn" and "trac" to the DNS configuration for your domain. Once this is done, Subversion and Trac will be integrated into your server environment, and will be accessible from the web.

Share this page:

8 Comment(s)