Edgewall Software

Recipe: Installing Trac with PostgreSQL on CentOS-4.2

This is a how-to on installing Trac-0.9.4 on Centos-4.2 (RH-ES4) with PostgreSQL-8.1.3 using psycopg2-2.

You should refer to the Trac documentation wiki at TracInstall. The instructions that follow are more specific to the given setup.

These instructions assume that you have superuser access to both the operating system and Postgresql as required. If this is not the case, then some of these activities must be performed on your behalf by a user with those privileges.

  1. Verify that Python is installed and note the version:
# rpm -qa python  		# should report something like: 
python-2.3.4-14.1.
  1. You will require the swig-py bindings for Trac. These must be built from the subversion source distribution. Note that as of subversion-1.2 the swig sources themselves are not required to build the Python bindings.
# cd ~/software
# curl http://subversion.tigris.org/downloads/subversion-1.3.0.tar.gz >  subversion-1.3.0.tar.gz
# tar -xvzf subversion-1.3.0.tar.gz
# cd subversion-1.3.0
# more README
# more INSTALL
# ./configure 
...

At this point, if you have a binary rpm of subversion ≥ 1.2 already installed, then you just need to make the swig bindings for Python. Otherwise, you need build and install Subversion first. We will not cover this eventuality here.

# <optional build and install of subversion>
...
# make swig-py
# make install-swig-py
#
  1. Verify that subversion is installed, configured and running:
# svn help
usage: svn <subcommand> [options] [args]
Subversion command-line client, version 1.3.0.
Type 'svn help <subcommand>' for help on a specific subcommand.
#
  1. Obtain a Postgresql adaptor for Python. This how-to employs psycopg2 which is obtained from http://initd.org/pub/software/psycopg/. Other possibilities are psycopg1 and pyPgSQL.
  1. Using curl, ftp or wget from the command line, or http from your web-browser, download the adaptor source into a working directory on the target machine, expand the archives, build and install the adaptor:
# cd ./software
# curl http://initd.org/pub/software/psycopg/psycopg2-2.0b8.tar.gz > psycopg2-2.0b8.tar.gz
# tar -xvzf psycopg2-2.0b8.tar.gz
# cd psycopg2-2.0b8
# more README
# more INSTALL
# python setup.py install
  1. Get Trac from TracDownload. Go to your working directory (cd ~/software) and download the Trac distribution that you wish to use:
# cd ~/software
# curl http://ftp.edgewall.com/pub/trac/trac-0.9.4.tar.gz > trac-0.9.4.tar.gz
# cd trac-0.9.4
# more README
# more INSTALL
...

You will note in the INSTALL notes the requirements for the Subversion swig-py bindings and Clearsilver. As detailed above, the former must be built locally from the subversion source distribution while the second can be obtained as an rpm for Red Hat EL-4 from http://dag.wieers.com/packages/clearsilver/. If all of the prerequisites are met, then install Trac:

# python ./setup.py install
  1. The utility trac-admin is used to setup Trac environments and to configure the environment thereafter. On Centos4 the Trac bindings are installed by default beneath "/usr/local/lib/svn-python" which must be added to the Python load path. This can be done through the environment variable PYTHONPATH:
# export PYTHONPATH=/usr/local/lib/svn-python

and adding a similar Apache httpd.conf SetEnv directive inside the relevant location. Alternatively, one can create a file called trac_svn.pth containing a single line:

/usr/local/lib/svn-python

and place this somewhere in Python's default load path. The file name is not important, but the .pth extension is. You can determine the default path thus:

# python
Python 2.3.4 (#1, Feb 22 2005, 04:09:37)
[GCC 3.4.3 20041212 (Red Hat 3.4.3-9.EL4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/usr/lib/python23.zip', '/usr/lib/python2.3', 
'/usr/lib/python2.3/plat-linux2', '/usr/lib/python2.3/lib-tk', 
'/usr/lib/python2.3/lib-dynload', '/usr/lib/python2.3/site-packages', 
'/usr/lib/python2.3/site-packages/setuptools-0.6a10-py2.3.egg', 
'/usr/lib/python2.3/site-packages/gtk-2.0']
>>><ctrl>D

Placing 'trac_svn.pth' in '/usr/lib/python2.3/site-packages' seems to me the best solution.

# echo /usr/local/lib/svn-python > /usr/lib/python2.3/site-packages/trac_svn.pth
# cat /usr/lib/python2.3/site-packages/trac_svn.pth
/usr/local/lib/svn-python
#
# python
Python 2.3.4 (#1, Feb 22 2005, 04:09:37)
[GCC 3.4.3 20041212 (Red Hat 3.4.3-9.EL4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys   # type this
>>> sys.path     # and then this
['', '/usr/lib/python23.zip', '/usr/lib/python2.3', 
'/usr/lib/python2.3/plat-linux2', '/usr/lib/python2.3/lib-tk', 
'/usr/lib/python2.3/lib-dynload', '/usr/lib/python2.3/site-packages', 
'/usr/lib/python2.3/site-packages/setuptools-0.6a10-py2.3.egg', 
'/usr/lib/python2.3/site-packages/gtk-2.0', '/usr/local/lib/svn-python']
>>><ctrl>D

We can see that /usr/local/lib/svn-python has been added to Python's search path. Note that a version upgrade of Python will require that we move trac_svn.pth to the new site-packages directory. Now trac-admin, apache and tracd should all find the necessary bindings and run without any further ado.

  1. At this point everything is wired up and ready to go with tracd as the server and SQLite3 as the backend database. You can create your first Trac environment:
# trac-admin /path/to/trac_project_env initenv 

You must answer the questions regarding the database connection and subversion repository. To use a different database backend you must first initialize the alternative database environment before running "trac-admin /path/to/trac_project_env initenv".

  1. To use Postgresql as the database backend you must first setup a target database user and a database instance to pass to trac-admin when it asks for a connection string. The postgresql command line utilities for this are createuser(1) and createdb(1).
# createuser --username <postgres user with CREATEROLE permission> \
#   --password --pwprompt --createdb --createrole --echo \ 
#   <trac_DB_admin_user_name>

Example:

# createuser --username superuser --password --pwprompt --createdb --createrole --echo trac_db_admin
Enter password for new role:
Enter it again:
Shall the new role be a superuser? (y/n) n
Password:
CREATE ROLE trac_db_admin PASSWORD 'trac2005' NOSUPERUSER CREATEDB 
CREATEROLE INHERIT LOGIN;
CREATE ROLE

The first set of password prompts are used to set the password for the new role being created. The second set is to authenticate the database connection. Read the man(1) page for createuser for further information and options.

Debian note: A typical postgresql authentication setup assumes that you connect to the postgresql database via the 'postgres' system user account for the first time using UNIX domain socket (the default) - see /etc/postgresql/8.x/main/pg_hba.conf

Next, create the database you wish to use using the new role just established:

# createdb [--host localhost] --username <trac_DB_admin_user_name> --password \ 
#   --owner <trac_DB_admin_user_name> --echo -E UTF8 <trac_DB_name>

Example:

# createdb --host localhost --username trac_db_admin --password --owner trac_db_admin --echo -E UTF8 trac_db
Password:
CREATE DATABASE trac_db OWNER trac_db_admin;
CREATE DATABASE

You have to provide the connection password again as above, but this time you use the password for trac_db_admin, since this was used to establish the connection. You can of course use any established postgresql user/role that has CREATEDB privileges instead.

Debian note : Note the —host option - since 'trac_db_admin' is only a postgresql database role it doesn't have a real system user counter part. Thus, you may not be able to connect via a Unix domain socket and have to use IPv4/6 socket (specified via —host). See the pga_hba.conf of your postgres configuration for details.

  1. With Trac and Postgresql all set up you must now determine the absolute path to the subversion repostor(y/ies) that you wish to use with Trac. This is a manual task. A typical repository path might look like "/var/data/svn" or "/var/svn".
  1. With the information obtained above, the postgresql database name, the path to the Trac directory, and the path to the subversion repository, we now invoke trac-admin to create the environment.
# trac-admin /var/data/trac initenv
Creating a new Trac environment at /var/data/trac

Trac will first ask a few questions about your environment
in order to initalize 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]> Harte & Lyne Limited

 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://trac_db_admin:<password>@<valid hostname or ip addr>/trac_db

 Please specify the absolute path to the project Subversion repository.
 Repository must be local, and trac-admin requires read+write
 permission to initialize the Trac database.

Path to repository [/var/svn/test]> /var/spool/svn

 Please enter location of Trac page templates.
 Default is the location of the site-wide templates installed with Trac.

Templates directory [/usr/share/trac/templates]>

Creating and Initializing Project
 Configuring Project
  trac.repository_dir
  trac.database
  trac.templates_dir
  project.name
 Installing default wiki pages
 /usr/share/trac/wiki-default/TracLogging => TracLogging
 /usr/share/trac/wiki-default/TracBackup => TracBackup
 /usr/share/trac/wiki-default/WikiFormatting => WikiFormatting
 /usr/share/trac/wiki-default/SandBox => SandBox
 /usr/share/trac/wiki-default/CamelCase => CamelCase
 /usr/share/trac/wiki-default/TracRss => TracRss
 /usr/share/trac/wiki-default/TracInstall => TracInstall
 /usr/share/trac/wiki-default/WikiRestructuredText => WikiRestructuredText
 /usr/share/trac/wiki-default/TracIni => TracIni
 /usr/share/trac/wiki-default/WikiProcessors => WikiProcessors
 /usr/share/trac/wiki-default/TracPlugins => TracPlugins
 /usr/share/trac/wiki-default/TracAccessibility => TracAccessibility
 /usr/share/trac/wiki-default/TracSearch => TracSearch
 /usr/share/trac/wiki-default/TracLinks => TracLinks
 /usr/share/trac/wiki-default/TitleIndex => TitleIndex
 /usr/share/trac/wiki-default/TracImport => TracImport
 /usr/share/trac/wiki-default/TracFastCgi => TracFastCgi
 /usr/share/trac/wiki-default/TracWiki => TracWiki
 /usr/share/trac/wiki-default/TracModPython => TracModPython
 /usr/share/trac/wiki-default/TracChangeset => TracChangeset
 /usr/share/trac/wiki-default/TracTicketsCustomFields => 

TracTicketsCustomFields
 /usr/share/trac/wiki-default/TracQuery => TracQuery
 /usr/share/trac/wiki-default/TracEnvironment => TracEnvironment
 /usr/share/trac/wiki-default/WikiHtml => WikiHtml
 /usr/share/trac/wiki-default/TracPermissions => TracPermissions
 /usr/share/trac/wiki-default/TracStandalone => TracStandalone
 /usr/share/trac/wiki-default/TracUpgrade => TracUpgrade
 /usr/share/trac/wiki-default/WikiDeletePage => WikiDeletePage
 /usr/share/trac/wiki-default/TracInterfaceCustomization => 

TracInterfaceCustomization
 /usr/share/trac/wiki-default/TracSyntaxColoring => TracSyntaxColoring
 /usr/share/trac/wiki-default/TracGuide => TracGuide
 /usr/share/trac/wiki-default/TracTickets => TracTickets
 /usr/share/trac/wiki-default/WikiMacros => WikiMacros
 /usr/share/trac/wiki-default/WikiPageNames => WikiPageNames
 /usr/share/trac/wiki-default/TracRoadmap => TracRoadmap
 /usr/share/trac/wiki-default/WikiNewPage => WikiNewPage
 /usr/share/trac/wiki-default/TracSupport => TracSupport
 /usr/share/trac/wiki-default/TracReports => TracReports
 /usr/share/trac/wiki-default/TracBrowser => TracBrowser
 /usr/share/trac/wiki-default/TracCgi => TracCgi
 /usr/share/trac/wiki-default/WikiStart => WikiStart
 /usr/share/trac/wiki-default/WikiRestructuredTextLinks => 

WikiRestructuredTextLinks
 /usr/share/trac/wiki-default/TracTimeline => TracTimeline
 /usr/share/trac/wiki-default/RecentChanges => RecentChanges
 /usr/share/trac/wiki-default/TracUnicode => TracUnicode
 /usr/share/trac/wiki-default/TracAdmin => TracAdmin
 /usr/share/trac/wiki-default/TracNotification => TracNotification
 Indexing repository

---------------------------------------------------------------------
Project environment for 'Harte & Lyne Limited Customs Brokerage' created.

You may now configure the environment by editing the file:

  /var/data/trac/conf/trac.ini

If you'd like to take this new project environment for a test drive, try running the Trac standalone web server `tracd`:

# tracd --port 8000 /var/data/trac

Then point your browser to `http://localhost:8000/trac`. There you can also browse the documentation for your installed version of Trac, including information on further setup (such as deploying Trac to a real web server).

The latest documentation can also always be found on the project website:

  http://projects.edgewall.com/trac/

Congratulations!
#

Trac is now installed and available. You can test it out using tracd:

# tracd --port <port-number> /var/data/trac

Example:

# tracd --port 3000 /var/data/trac
brms-02.brockley.harte-lyne.ca - - [06/Mar/2006 14:13:10] "GET / HTTP/1.1" 
200 -
brms-02.brockley.harte-lyne.ca - - [06/Mar/2006 14:13:11] "GET /trac 
HTTP/1.1" 200 -
brms-02.brockley.harte-lyne.ca - - [06/Mar/2006 14:13:11] "GET 
/trac/chrome/common/css/trac.css HTTP/1.1" 200 -
brms-02.brockley.harte-lyne.ca - - [06/Mar/2006 14:13:11] "GET 
/trac/chrome/common/css/wiki.css HTTP/1.1" 200 -
brms-02.brockley.harte-lyne.ca - - [06/Mar/2006 14:13:11] "GET 
/trac/chrome/common/css/code.css HTTP/1.1" 200 -
brms-02.brockley.harte-lyne.ca - - [06/Mar/2006 14:13:11] "GET 
/trac/chrome/common/trac.ico HTTP/1.1" 200 -
brms-02.brockley.harte-lyne.ca - - [06/Mar/2006 14:13:11] "GET 
/trac/chrome/common/js/trac.js HTTP/1.1" 200 -
brms-02.brockley.harte-lyne.ca - - [06/Mar/2006 14:13:12] "GET 
/trac/chrome/common/trac_banner.png HTTP/1.1" 200 -
brms-02.brockley.harte-lyne.ca - - [06/Mar/2006 14:13:12] "GET 
/trac/chrome/common/trac_logo_mini.png HTTP/1.1" 200 -
brms-02.brockley.harte-lyne.ca - - [06/Mar/2006 14:13:12] "GET 
/trac/chrome/common/topbar_gradient.png HTTP/1.1" 200 -
brms-02.brockley.harte-lyne.ca - - [06/Mar/2006 14:13:12] "GET 
/trac/chrome/common/topbar_gradient2.png HTTP/1.1" 200 -
brms-02.brockley.harte-lyne.ca - - [06/Mar/2006 14:13:12] "GET 
/trac/chrome/common/dots.gif HTTP/1.1" 200 -
brms-02.brockley.harte-lyne.ca - - [06/Mar/2006 14:13:12] "GET 
/trac/chrome/common/extlink.gif HTTP/1.1" 200 -

Everything seems to work.

  1. You will now need to customize your Trac installation to suit your project needs. Configuration is carried out through both the trac-admin command line interface (adding and removing trac users, adding, changing or removing priority and severity codes, adding and removing milestones, etc.) and by directly editing the .trac/conf/trac.ini file (setting email and default values for the web interface). See TracIni.

To find out more about trac-admin just run it:

# trac-admin /var/data/trac
Trac [/var/data/trac]> help
...

Or visit TracAdmin.

More advanced customization is accomplished by modifying or replacing the stylesheets in .trac/templates.

  1. You will at some point wish to use Trac plugins. To employ plugins you must install or upgrade setuptools for Python. The easiest way to do this is to obtain ez_setup.py from http://peak.telecommunity.com/DevCenter/setuptools and run it as root "#python ez_setup.py". You can get more information about plugins for Trac at TracPlugins.

For information on configuring Apache to run Trac see TracModPython. For alternative methods for installing on Red Hat type systems, particularly Fedora Core see TracOnFedoraCore.

Last modified 2 weeks ago Last modified on Nov 9, 2017, 12:53:55 AM
Note: See TracWiki for help on using the wiki.