How to install and configure Trac for use in professional development environments. Trac will run as a module in Apache2 and will use it's own database in sqlite or PostgreSQL. Subversion is also integrated. The whole thing will be visible at http://code.domain.tld/trac
These are sample USE flags when running under Apache.
[ebuild R ] www-apache/mod_python-3.3.1-r1 438 kB [ebuild R ] www-apps/trac-0.12 USE="-cgi -fastcgi -i18n -mysql postgres sqlite subversion vhosts" 0 kB
Configure apache to start with mod_python by editing /etc/conf.d/apache2 to look something like the following. Restart apache.
APACHE2_OPTS="-D SSL -D PHP5 -D PYTHON -D XSENDFILE"
Then run the Trac easy installer
www-host ~ # easy_install Trac
Shell into the database server and create a dedicate user and database for Trac. Other methods exist but this is plain and simple.
sql-host ~ # psql -U postgres postgres=# create user my_trac with encrypted password 'password'; postgres=# create database my_trac with owner = my_trac encoding = 'UTF8';
This Trac repository is created on a raid array but, could be to any path needed.
www-host ~ # # trac-admin /mnt/raid/trac initenv Creating a new Trac environment at /mnt/raid/trac Trac will first ask a few questions about your environment in order to initialize and prepare the project database. Please enter the name of your project. This name will be used in page titles and descriptions. Project Name [My Project]> My Trac Project is Awesome Please specify the connection string for the database to use. By default, a local SQLite database is created in the environment directory. It is also possible to use an already existing PostgreSQL database (check the Trac documentation for the exact connection string syntax). Database connection string [sqlite:db/trac.db]> postgres://my_trac:password@sql-host/my_trac Please specify the type of version control system, By default, it will be svn. If you don't want to use Trac with version control integration, choose the default here and don't specify a repository directory. in the next question. Repository type [svn]> Please specify the absolute path to the version control repository, or leave it blank to use Trac without a repository. You can also set the repository location later. Path to repository [/path/to/repos]> /mnt/raid/svn [ a bundle of snipped output here ] Congratulations!
Change permissions so Apache can see the whole thing.
www-host ~ # chown -R apache:apache /mnt/raid/trac
Edit the trac configuration in /mnt/raid/trac/conf/trac.ini and adjust the following, unchanged values are just not listed here. First set changes logo, second set change email behaviour.
[header_logo] alt = Logo link = http://code.domain.tld/trac src = http://code.domain.tld/img/logo.png [notification] always_notify_owner = true always_notify_updater = false smtp_default_domain = domain.tld smtp_from = firstname.lastname@example.org smtp_from_name = Trac smtp_password = password smtp_replyto = email@example.com smtp_server = smtp.domain.tld smtp_user = firstname.lastname@example.org
This example creates a dedicated site at trac.domain.tld. Create a file such as this in /etc/apache2/vhosts.d/trac.domain.tld.conf
<VirtualHost 126.96.36.199:80> DocumentRoot /var/www/domain.tld/ ServerName code.domain.tld # # Trac Sites # <Location /trac> SetHandler mod_python PythonInterpreter main_interpreter PythonHandler trac.web.modpython_frontend PythonOption TracEnv /mnt/raid/trac PythonOption TracUriRoot /trac # HTML pages can only be 90 seconds old (keeps fresh) ExpiresByType text/html "access plus 90 seconds" # Set some authentication - could use Digest AuthType Basic AuthName "My Trac Project" AuthUserFile /mnt/raid/trac/conf/htpasswd Require valid-user </Location> # @todo include your subversion location here </VirtualHost>
And well need a few users too
www-host ~ # htpasswd -bc /mnt/raid/trac/conf/htpasswd code password
This configuration example restricts Trac usage to to subnets and authenticates to a back-end LDAP system. This should be placed into the <Location> section.
Order deny,allow Deny from all Allow from 192.168.1.0/24 Allow from 192.168.100.0/24 AuthType Basic AuthName "My Trac Server" AuthBasicProvider "ldap" AuthLDAPURL "ldap://ldap/dc=domain,dc=com?uid?sub?(objectClass=posixAccount)" AuthzLDAPAuthoritative Off Require valid-user
Out of the box Trac is very useful but here are a few plugins that we thing are "must have".
This plugin will allow interaction to Trac via XML-RPC from programs/scripts in almost any language. Installation is quite simple, the process will look something like this.
root@host # easy_install -Z -U http://trac-hacks.org/svn/xmlrpcplugin/trunk install_dir /usr/lib/python2.6/site-packages/ Downloading http://trac-hacks.org/svn/xmlrpcplugin/trunk Doing subversion checkout from http://trac-hacks.org/svn/xmlrpcplugin/trunk to /tmp/easy_install-NeNWSz/trunk Processing trunk Running setup.py -q bdist_egg --dist-dir /tmp/easy_install-NeNWSz/trunk/egg-dist-tmp-0m1XdM Adding TracXMLRPC 1.1.0-r9395 to easy-install.pth file Installed /usr/lib/python2.6/site-packages/TracXMLRPC-1.1.0_r9395-py2.6.egg Processing dependencies for TracXMLRPC==1.1.0-r9395 Finished processing dependencies for TracXMLRPC==1.1.0-r9395
Once that is done, update trac.ini to include this plugin, the restart Apache for good measure.
[components] tracrpc.* = enabled
See their Trac Hacks - XML RPC.