Edgewall Software

Install Trac 0.12 with Bazaar ,MySQL and Mod_WSGI on Ubuntu 10.04

This tutorial describes how to install Trac 0.12 on Ubuntu 10.04. I assume this would work for and older ubuntu or Debian with minor modifications. It will use MySQL as the Database, Mod_WSGI as the apache module and Bazaar as Source Control (VCS).

The tutorial assumes that your project will be called newproject. If you are not familiar with vi you can change the vi commands to nano, joe or whatever you like. I do not make any guarantee this will work for you.

Install a base ubuntu server (this should work for a desktop install as well). I selected ssh during install so I could get into the machine.

Update the System:

sudo apt-get update && sudo apt-get upgrade
sudo reboot

Install base packages:

sudo apt-get install apache2 libapache2-mod-wsgi python-setuptools python-genshi mysql-server python-mysqldb bzr

(optional):

sudo apt-get install python-pybabel python-docutils python-pygments python-tz

Enter MySQL root password during mysql install.

Install Trac:

sudo easy_install Trac==0.12

This will also install a Geshi egg

Setup Database.

Log into MySQL:

mysql -u root -p yourpassword

Once logged in, run these mysql commands:

CREATE DATABASE trac DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;

Create MySQL Password:

GRANT ALL ON trac.* TO tracuser@localhost IDENTIFIED BY 'yourpassword';

Change yourpassword to whatever you want the password to be.

exit

Create a Project:

I am going to put the trac projects under /var/tracprojects/. The name of the new project is newproject.

sudo mkdir /var/tracprojects
sudo mkdir /var/tracprojects/newproject
sudo trac-admin /var/tracprojects/newproject initenv

Enter your projects name (newproject) and press enter:

Project Name [My Project]> newproject (press enter)

Enter the MySQL connection string and press enter:

Database connection string [sqlite:db/trac.db]> mysql://tracuser:yourpassword@localhost/trac (press enter)

Convert MyISAM tables:

Now we need to convert the mysql tables to INNODB

Log back into mysql:

mysql -u root -pyourpassword
USE trac;
SELECT table_name, engine FROM information_schema.tables WHERE table_schema=DATABASE();

If the engine is MYISAM it must be converted.

Run the folowing mysql commands on the trac database as one command and press enter at the end to complete the statments:

ALTER TABLE `attachment` ENGINE = InnoDB; \
ALTER TABLE `auth_cookie` ENGINE = InnoDB; \
ALTER TABLE `cache` ENGINE = InnoDB; \
ALTER TABLE `component` ENGINE = InnoDB; \
ALTER TABLE `enum` ENGINE = InnoDB; \
ALTER TABLE `milestone` ENGINE = InnoDB; \
ALTER TABLE `node_change` ENGINE = InnoDB; \
ALTER TABLE `permission` ENGINE = InnoDB; \
ALTER TABLE `report` ENGINE = InnoDB; \
ALTER TABLE `repository` ENGINE = InnoDB; \
ALTER TABLE `revision` ENGINE = InnoDB; \
ALTER TABLE `session` ENGINE = InnoDB; \
ALTER TABLE `session_attribute` ENGINE = InnoDB; \
ALTER TABLE `system` ENGINE = InnoDB; \
ALTER TABLE `ticket` ENGINE = InnoDB; \
ALTER TABLE `ticket_change` ENGINE = InnoDB; \
ALTER TABLE `ticket_custom` ENGINE = InnoDB; \
ALTER TABLE `version` ENGINE = InnoDB; \
ALTER TABLE `wiki` ENGINE = InnoDB;

Recheck that all database types are InnoDB:

SELECT table_name, engine FROM information_schema.tables WHERE table_schema=DATABASE();
exit

Deploy the Project (this creates the .wsgi file):

sudo trac-admin /var/tracprojects/newproject/ deploy /var/tracprojects/newproject/deploy

Change permissions to apache on the project:

sudo chown -R www-data:www-data /var/tracprojects/newproject/

Set apache for wsgi:

sudo vi /etc/apache2/conf.d/trac.newproject.conf

Paste the following contents into the file and save it:

 WSGIScriptAlias /newproject /var/tracprojects/newproject/deploy/cgi-bin/trac.wsgi

    <Directory /var/tracprojects/newproject/deploy/cgi-bin>
     WSGIApplicationGroup %{GLOBAL}
     Order deny,allow
     Allow from all
    </Directory>

    <Location "/trac/login">
     AuthType Basic
     AuthName "Trac"
     AuthUserFile /var/tracprojects/.htpasswd
     Require valid-user
    </Location>

 WSGIScriptAliasMatch ^/repo/.*/\.bzr/smart$ /var/tracprojects/newproject/deploy/cgi-bin/bzr.wsgi

     #The three next lines allow regular GETs to work too
     RewriteEngine On
     RewriteCond %{REQUEST_URI} !^/code/.*/\.bzr/smart$
     RewriteRule ^/code/(.*/\.bzr/.*)$ /var/tracprojects/newproject/repo/ [L]

    <Directory /var/tracprojects/newproject/repo/>
     WSGIApplicationGroup %{GLOBAL}
    </Directory>

    <Location /repo/>
     AuthType Basic
     AuthName "Trac Source Access"
     AuthUserFile /var/tracprojects/.htpasswd
    <LimitExcept GET>
        Require valid-user
    </LimitExcept>
    </Location>

If you have login trouble with this code, (Because login link is http://localhost/newproject/login)

   <Location "/trac/login">
     AuthType Basic
     AuthName "Trac"
     AuthUserFile /var/tracprojects/.htpasswd
     Require valid-user
    </Location>

You can use this code

    <Location "/newproject/login">
     AuthType Basic
     AuthName "Trac"
     AuthUserFile /var/tracprojects/.htpasswd
     Require valid-user
    </Location>

We will use the same .htpasswd to authenticate bzr users as the trac install. Anyone you give access to trac will have write access to the bzr repo. You can change the bzr.wsgi setting readonly to true to disable any write access (see below). You could also create a different .htpasswd to seperate trac from bzr or require certain users by changing Require valid-user to Require admin.

Run the following command to create a password for user admin:

sudo htpasswd -c /var/tracprojects/.htpasswd admin

Enter your password twice.

Grant admin rights to user admin:

trac-admin /var/tracprojects/newproject permission add admin TRAC_ADMIN

Enable rewrite in apache:

sudo a2enmod rewrite

Enable wsgi in apache:

sudo a2enmod wsgi

Now restart Apache:

sudo /etc/init.d/apache2 restart

See if it worked:

Go to http://your-host/newproject

Everything should be working. You should be able to login.

Now we need to setup bazaar as our vcs.

Install the Trac Bazaar plugin:

sudo easy_install TracBzr
sudo mkdir /var/tracprojects/newproject/repo
sudo chown www-data:www-data /var/tracprojects/newproject/repo/

Open the config file:

sudo vi /var/tracprojects/newproject/conf/trac.ini

Find the section [trac]. Change repository_dir and repository_type to look like this:

repository_dir = /var/tracprojects/newproject/repo
repository_type = bzr

Add this to the bottom of the file:

[components]
tracbzr.* = enabled

Save the file.

Create the bzr access file. We will create this in the deploy/cgi-bin directory:

sudo vi /var/tracprojects/newproject/deploy/cgi-bin/bzr.wsgi

Paste this in the file:

from bzrlib.transport.http import wsgi

def application(environ, start_response):
    app = wsgi.make_app(
        root="/var/tracprojects/newproject/repo/",
        prefix="/repo",
        readonly=False,
        enable_logging=False)
    return app(environ, start_response)

Restart apache:

sudo /etc/init.d/apache2 restart

You should be able to the the Browse Source link at the top. You will see an error because there is no source yet.

Create the bzr repo on the server:

cd /var/tracprojects/newproject/
sudo bzr whoami "Your Name <youremail@mymail.com>"
sudo bzr init-repo --no-trees repo/
sudo chown -R www-data:www-data /var/tracprojects/newproject/repo/

Now initialize the project from the client; first, go back to your home (or other working dir):

cd ~
bzr whoami "Your Name <youremail@mymail.com>"
bzr init bzr+http://tracserver/repo/newproject
bzr checkout bzr+http://tracserver/repo/newproject dev
cd dev
touch test.txt
bzr add
bzr commit -m "Added test.txt"

If you get any errors when commiting make sure perrmissions are set to apache on the server:

sudo chown -R www-data:www-data /var/tracprojects/newproject/repo/

Now go to http://your-host/newproject and click on Browse Source and you should be able to browse the source.

I recommend a GUI app called Bazaar Explorer. See http://wiki.bazaar.canonical.com/BzrExplorer

Optional

You can optionally install the default ssl on ubuntu by running:

sudo a2enmod ssl
sudo a2ensite default-ssl
sudo /etc/init.d/apache2 restart

I had to remove python-pycurl on my Ubuntu client to connect to the bzr repo through https:

sudo apt-get remove python-pycurl

use:

bzr checkout bzr+https://tracserver/repo/newproject dev

instead of:

bzr checkout bzr+http://tracserver/repo/newproject dev

Resources:

Last modified 13 years ago Last modified on Feb 17, 2012, 2:24:45 PM
Note: See TracWiki for help on using the wiki.