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

Want to support HowtoForge? Become a subscriber!
 
Submitted by colan (Contact Author) (Forums) on Wed, 2008-01-09 17:31. :: Debian | Ubuntu | Apache | Programming

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.


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by kevin (not registered) on Thu, 2012-01-12 16:06.
This can't be right since apache does not even support name based virtualhosts with ssl.  Both svn and trac point to port 443. 
Submitted by philippe Beaucart (not registered) on Tue, 2010-05-25 00:25.

Many thx for the clear and complete description.

Did not work for me with adding a new vhost site in the sites-available, but with adding a vhost as in the past with apache1.3. I guess because of my own set up.

Submitted by civil777 (not registered) on Sat, 2011-05-28 19:59.

If you are creating name-based virtual hosts, make sure to add the following directive to the top of /etc/apache2/ports.conf

If using SSL:

NameVirtualHost [Your Server's IP Addr]:443

If not using SSL:

NameVirtualHost [Your Server's IP Addr]:80

Submitted by mtnpaul (not registered) on Wed, 2009-08-26 00:15.

Since development/support in mod_python seems to be drawing to a close perhaps it would be best to update this for mod_wsgi.

 

 

Submitted by Jember (not registered) on Sun, 2009-04-19 15:56.

Thanks for the howto guys, virtual host is working fine.

Submitted by Richie (not registered) on Thu, 2008-10-30 18:26.

Very good tutorial except for a small bit of detail:

 You suddenly spring in:

/usr/share/trac/htdocs
Where did this come from, what does it represent, a blank website?
Yours questioningly, Richie 
Submitted by Sel (not registered) on Fri, 2009-07-24 10:12.

oops forgot about my system details. Here they are:

trac: v0.10.3,
system: debian etch,
interpreter: python 2.4,
server: apache 2.2.3

Submitted by Sel (not registered) on Fri, 2009-07-24 10:08.

Hi,

I have a problem with this configuration (or with my system configuration).

Lat's say there are two of us, user named szymon and user waldek.
Waldek is logging in to trac and after this szymon logs in and a strange situation occurs: waldek can see that he is logged as szymon and szymon is logged as waldek.

How to prevent user's inflitrating?
Please help me with this issue.

Thanks from the mountains:)