Edgewall Software

Changes between Initial Version and Version 1 of PostgresqlRecipe


Ignore:
Timestamp:
Mar 6, 2006, 9:17:39 PM (18 years ago)
Author:
byrnejb@…
Comment:

New page recipe for setting up trac and postgresql

Legend:

Unmodified
Added
Removed
Modified
  • PostgresqlRecipe

    v1 v1  
     1== Recipe Trac and PostgreSQL ==
     2
     3
     4HOWTO:
     5Install trac-0.9.4 on Centos4 (RH-ES4) with PostgreSQL-8.1.3 using psycopg2-2.
     6
     7You should refer to the trac documentation wiki for current details respecting installing trac at [wiki:TracInstall]. 
     8
     9The instructions that follow are more detailed but the details are likely to date swiftly.
     10
     11These 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.  I do not attempt to systematically identify those tasks that require superuser capability.
     12
     131.  Verify that Python is installed and note the version;
     14
     15
     16{{{
     17#
     18# rpm -qa python                # should report something like:
     19python-2.3.4-14.1.
     20#
     21
     22}}}
     23
     242.  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.
     25
     26
     27{{{
     28#
     29# cd ~/software
     30# curl http://subversion.tigris.org/downloads/subversion-1.3.0.tar.gz >  subversion-1.3.0.tar.gz
     31# tar -xvzf subversion-1.3.0.tar.gz
     32# cd subversion-1.3.0
     33# more README
     34# more INSTALL
     35# ./configure
     36
     37}}}
     38
     39At 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 itself first.  We will
     40not cover this eventuality here.
     41
     42
     43{{{
     44#
     45# <optional build and install of subversion
     46...
     47# make swig-py
     48# make install-swig-py
     49#
     50}}}
     51
     52
     533.  Verify that subversion is installed, configured, and running:
     54
     55
     56{{{
     57# svn help
     58usage: svn <subcommand> [options] [args]
     59Subversion command-line client, version 1.3.0.
     60Type 'svn help <subcommand>' for help on a specific subcommand.
     61#
     62}}}
     63
     64
     65
     664.  Obtain a postgresql adaptor for python. This HOWTO employs psycopg2 which is obtained from [http://initd.org/pub/software/psycopg]/. Other possibilites are psycopg1 and pyPgSQL.  Google is your friend here.
     67
     685.   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.
     69
     70
     71{{{
     72#
     73# cd ./software
     74# curl curl http://initd.org/pub/software/psycopg/psycopg2-2.0b8.tar.gz > psycopg2-2.0b8.tar.gz
     75# tar -xvzf psycopg2-2.0b8.tar.gz
     76# cd psycopg2-2.0b8
     77# more README
     78# more INSTALL
     79# python setup.py install
     80#
     81}}}
     82
     83
     846.  Now get trac from [wiki:TracDownload]. Move to your working directory (cd ~/software) and download the trac distribution that you wish to use.
     85
     86
     87{{{
     88#
     89# cd ~/software
     90# curl http://ftp.edgewall.com/pub/trac/trac-0.9.4.tar.gz > trac-0.9.4.tar.gz
     91# cd trac-0.9.4
     92# more README
     93# more INSTALL
     94#
     95}}}
     96
     97
     98You 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:
     99 
     100
     101{{{
     102# python ./setup.py install
     103#
     104
     105}}}
     106
     1077.  The utiltiy 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:
     108
     109
     110{{{
     111#
     112# export PYTHONPATH=/usr/local/lib/svn-python
     113#
     114}}}
     115
     116
     117and adding a similar Apache httpd.conf SetEnv directive inside the relevent location.  ALternatively, one can create a file called trac_svn.pth containing a single line:
     118
     119/usr/local/lib/svn-python
     120
     121and place this somewhere in python's default load path.  The file name is not important, but the .pth extension is. You can determine
     122the default path thus:
     123
     124
     125{{{
     126#
     127# python
     128Python 2.3.4 (#1, Feb 22 2005, 04:09:37)
     129[GCC 3.4.3 20041212 (Red Hat 3.4.3-9.EL4)] on linux2
     130Type "help", "copyright", "credits" or "license" for more information.
     131>>> import sys
     132>>> sys.path
     133['', '/usr/lib/python23.zip', '/usr/lib/python2.3',
     134'/usr/lib/python2.3/plat-linux2', '/usr/lib/python2.3/lib-tk',
     135'/usr/lib/python2.3/lib-dynload', '/usr/lib/python2.3/site-packages',
     136'/usr/lib/python2.3/site-packages/setuptools-0.6a10-py2.3.egg',
     137'/usr/lib/python2.3/site-packages/gtk-2.0']
     138>>><ctrl>D
     139#
     140}}}
     141
     142
     143Placing 'trac_svn.pth' in '/usr/lib/python2.3/site-packages' seems to me the best solution.
     144
     145
     146{{{
     147#
     148# echo /usr/local/lib/svn-python > \
     149# /usr/lib/python2.3/site-packages/trac_svn.pth
     150#
     151# cat /usr/lib/python2.3/site-packages/trac_svn.pth \
     152# /usr/local/lib/svn-python
     153#
     154# python
     155Python 2.3.4 (#1, Feb 22 2005, 04:09:37)
     156[GCC 3.4.3 20041212 (Red Hat 3.4.3-9.EL4)] on linux2
     157Type "help", "copyright", "credits" or "license" for more information.
     158>>> import sys   # type this
     159>>> sys.path     # and then this
     160['', '/usr/lib/python23.zip', '/usr/lib/python2.3',
     161'/usr/lib/python2.3/plat-linux2', '/usr/lib/python2.3/lib-tk',
     162'/usr/lib/python2.3/lib-dynload', '/usr/lib/python2.3/site-packages',
     163'/usr/lib/python2.3/site-packages/setuptools-0.6a10-py2.3.egg',
     164'/usr/lib/python2.3/site-packages/gtk-2.0', '/usr/local/lib/svn-python']
     165>>><ctrl>D
     166#
     167}}}
     168
     169
     170Now trac-admin, apache and tracd should all find the necessary bindings
     171and run without any further ado.
     172
     1738.  At this point evrything is wired up and ready to go with tracd as the
     174server and SQLite3 as the backend database.  You can create your first
     175trac environment by issueing the following command:
     176
     177
     178{{{
     179#
     180# trac-admin /path/to/trac_project_env initenv
     181#
     182}}}
     183
     184
     185and answering the questions regarding the database connection and
     186subversion repository. To use a different DB backend you must first
     187initialize the alternative database environment before runing trac-admin. 
     188
     1899.  To use postgresql as the backend one must first setup a target
     190database user and database to pass to trac-admin when it asks for a
     191connection string.  The postgresql command line utilities for this are
     192createuser(1) and createdb(1).
     193
     194
     195{{{
     196#
     197# createuser --username <postgres user with CREATEROLE permission> \
     198#   --password --pwprompt --createdb --createrole --echo \
     199#   <trac_DB_admin_user_name>
     200#
     201}}}
     202
     203
     204Example:
     205
     206
     207{{{
     208#
     209# createuser --username superuser --password --pwprompt --createdb
     210--createrole --echo trac_db_admin
     211
     212Enter password for new role:
     213Enter it again:
     214Shall the new role be a superuser? (y/n) n
     215Password:
     216CREATE ROLE trac_db_admin PASSWORD 'trac2005' NOSUPERUSER CREATEDB
     217CREATEROLE INHERIT LOGIN;
     218CREATE ROLE
     219#
     220}}}
     221
     222
     223The first set of password prompts are used to set the password for the new
     224role. The second set is to authenticate the database connection.  Read the
     225man(1) page for createuser for further information and options.
     226Next, create the database you wish to use using the new role just
     227established:
     228
     229
     230{{{
     231#
     232# createdb --username <trac_DB_admin_user_name> --password \
     233#   --owner <trac_DB_admin_user_name> --echo <trac_DB_name>
     234#
     235}}}
     236
     237
     238Example:
     239
     240
     241{{{
     242#
     243# createdb --username trac_db_admin --password --owner trac_db_admin --echo trac_db
     244Password:
     245CREATE DATABASE trac_db OWNER trac_db_admin;
     246CREATE DATABASE
     247#
     248}}}
     249
     250
     251You have to provide the connection password again as above, but this time
     252you use the password for trac_db_admin since this was used to establish
     253the connection.  You can of course use any established postgresql
     254user/role that has CREATEDB priviliges instead.
     255
     25610.  With trac and postgresql all set up you must now determine the
     257absolute 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
     258like "/var/data/svn" or "/var/svn".
     259
     26011.  With the information obtained above, the postgresql database name,
     261the path to the trac directory, and the path to the subversion repository,
     262we now invoke trac-admin to create the environment.
     263
     264#
     265{{{
     266
     267# trac-admin /var/data/trac initenv
     268Creating a new Trac environment at /var/data/trac
     269
     270Trac will first ask a few questions about your environment
     271in order to initalize and prepare the project database.
     272
     273 Please enter the name of your project.
     274 This name will be used in page titles and descriptions.
     275
     276Project Name [My Project]> Harte & Lyne Limited
     277
     278 Please specify the connection string for the database to use.
     279 By default, a local SQLite database is created in the environment
     280 directory. It is also possible to use an already existing
     281 PostgreSQL database (check the Trac documentation for the exact
     282 connection string syntax).
     283
     284Database connection string [sqlite:db/trac.db]>
     285
     286postgres://trac_db_admin:<password>@<valid hostname or ip addr>/trac_db
     287
     288 Please specify the absolute path to the project Subversion repository.
     289 Repository must be local, and trac-admin requires read+write
     290 permission to initialize the Trac database.
     291
     292Path to repository [/var/svn/test]> /var/spool/svn
     293
     294 Please enter location of Trac page templates.
     295 Default is the location of the site-wide templates installed with Trac.
     296
     297Templates directory [/usr/share/trac/templates]>
     298
     299Creating and Initializing Project
     300 Configuring Project
     301  trac.repository_dir
     302  trac.database
     303  trac.templates_dir
     304  project.name
     305 Installing default wiki pages
     306 /usr/share/trac/wiki-default/TracLogging => TracLogging
     307 /usr/share/trac/wiki-default/TracBackup => TracBackup
     308 /usr/share/trac/wiki-default/WikiFormatting => WikiFormatting
     309 /usr/share/trac/wiki-default/SandBox => SandBox
     310 /usr/share/trac/wiki-default/CamelCase => CamelCase
     311 /usr/share/trac/wiki-default/TracRss => TracRss
     312 /usr/share/trac/wiki-default/TracInstall => TracInstall
     313 /usr/share/trac/wiki-default/WikiRestructuredText => WikiRestructuredText
     314 /usr/share/trac/wiki-default/TracIni => TracIni
     315 /usr/share/trac/wiki-default/WikiProcessors => WikiProcessors
     316 /usr/share/trac/wiki-default/TracPlugins => TracPlugins
     317 /usr/share/trac/wiki-default/TracAccessibility => TracAccessibility
     318 /usr/share/trac/wiki-default/TracSearch => TracSearch
     319 /usr/share/trac/wiki-default/TracLinks => TracLinks
     320 /usr/share/trac/wiki-default/TitleIndex => TitleIndex
     321 /usr/share/trac/wiki-default/TracImport => TracImport
     322 /usr/share/trac/wiki-default/TracFastCgi => TracFastCgi
     323 /usr/share/trac/wiki-default/TracWiki => TracWiki
     324 /usr/share/trac/wiki-default/TracModPython => TracModPython
     325 /usr/share/trac/wiki-default/TracChangeset => TracChangeset
     326 /usr/share/trac/wiki-default/TracTicketsCustomFields =>
     327
     328TracTicketsCustomFields
     329 /usr/share/trac/wiki-default/TracQuery => TracQuery
     330 /usr/share/trac/wiki-default/TracEnvironment => TracEnvironment
     331 /usr/share/trac/wiki-default/WikiHtml => WikiHtml
     332 /usr/share/trac/wiki-default/TracPermissions => TracPermissions
     333 /usr/share/trac/wiki-default/TracStandalone => TracStandalone
     334 /usr/share/trac/wiki-default/TracUpgrade => TracUpgrade
     335 /usr/share/trac/wiki-default/WikiDeletePage => WikiDeletePage
     336 /usr/share/trac/wiki-default/TracInterfaceCustomization =>
     337
     338TracInterfaceCustomization
     339 /usr/share/trac/wiki-default/TracSyntaxColoring => TracSyntaxColoring
     340 /usr/share/trac/wiki-default/TracGuide => TracGuide
     341 /usr/share/trac/wiki-default/TracTickets => TracTickets
     342 /usr/share/trac/wiki-default/WikiMacros => WikiMacros
     343 /usr/share/trac/wiki-default/WikiPageNames => WikiPageNames
     344 /usr/share/trac/wiki-default/TracRoadmap => TracRoadmap
     345 /usr/share/trac/wiki-default/WikiNewPage => WikiNewPage
     346 /usr/share/trac/wiki-default/TracSupport => TracSupport
     347 /usr/share/trac/wiki-default/TracReports => TracReports
     348 /usr/share/trac/wiki-default/TracBrowser => TracBrowser
     349 /usr/share/trac/wiki-default/TracCgi => TracCgi
     350 /usr/share/trac/wiki-default/WikiStart => WikiStart
     351 /usr/share/trac/wiki-default/WikiRestructuredTextLinks =>
     352
     353WikiRestructuredTextLinks
     354 /usr/share/trac/wiki-default/TracTimeline => TracTimeline
     355 /usr/share/trac/wiki-default/RecentChanges => RecentChanges
     356 /usr/share/trac/wiki-default/TracUnicode => TracUnicode
     357 /usr/share/trac/wiki-default/TracAdmin => TracAdmin
     358 /usr/share/trac/wiki-default/TracNotification => TracNotification
     359 Indexing repository
     360
     361---------------------------------------------------------------------
     362Project environment for 'Harte & Lyne Limited Customs Brokerage' created.
     363
     364You may now configure the environment by editing the file:
     365
     366  /var/data/trac/conf/trac.ini
     367
     368If you'd like to take this new project environment for a test drive,
     369try running the Trac standalone web server `tracd`:
     370
     371# tracd --port 3000 /var/data/trac
     372
     373Then point your browser to http://localhost:8000/trac.
     374There you can also browse the documentation for your installed
     375version of Trac, including information on further setup (such as
     376deploying Trac to a real web server).
     377
     378The latest documentation can also always be found on the project
     379website:
     380
     381  http://projects.edgewall.com/trac/
     382
     383Congratulations!
     384#
     385}}}
     386
     387
     388Trac is now installed and available.  You can test it out using tracd.
     389
     390#
     391# tracd --port <port-number> /var/data/trac
     392#
     393
     394Example:
     395
     396
     397
     398{{{
     399#
     400# tracd --port 3000 /var/data/trac
     401brms-02.brockley.harte-lyne.ca - - [06/Mar/2006 14:13:10] "GET / HTTP/1.1"
     402200 -
     403brms-02.brockley.harte-lyne.ca - - [06/Mar/2006 14:13:11] "GET /trac
     404HTTP/1.1" 200 -
     405brms-02.brockley.harte-lyne.ca - - [06/Mar/2006 14:13:11] "GET
     406/trac/chrome/common/css/trac.css HTTP/1.1" 200 -
     407brms-02.brockley.harte-lyne.ca - - [06/Mar/2006 14:13:11] "GET
     408/trac/chrome/common/css/wiki.css HTTP/1.1" 200 -
     409brms-02.brockley.harte-lyne.ca - - [06/Mar/2006 14:13:11] "GET
     410/trac/chrome/common/css/code.css HTTP/1.1" 200 -
     411brms-02.brockley.harte-lyne.ca - - [06/Mar/2006 14:13:11] "GET
     412/trac/chrome/common/trac.ico HTTP/1.1" 200 -
     413brms-02.brockley.harte-lyne.ca - - [06/Mar/2006 14:13:11] "GET
     414/trac/chrome/common/js/trac.js HTTP/1.1" 200 -
     415brms-02.brockley.harte-lyne.ca - - [06/Mar/2006 14:13:12] "GET
     416/trac/chrome/common/trac_banner.png HTTP/1.1" 200 -
     417brms-02.brockley.harte-lyne.ca - - [06/Mar/2006 14:13:12] "GET
     418/trac/chrome/common/trac_logo_mini.png HTTP/1.1" 200 -
     419brms-02.brockley.harte-lyne.ca - - [06/Mar/2006 14:13:12] "GET
     420/trac/chrome/common/topbar_gradient.png HTTP/1.1" 200 -
     421brms-02.brockley.harte-lyne.ca - - [06/Mar/2006 14:13:12] "GET
     422/trac/chrome/common/topbar_gradient2.png HTTP/1.1" 200 -
     423brms-02.brockley.harte-lyne.ca - - [06/Mar/2006 14:13:12] "GET
     424/trac/chrome/common/dots.gif HTTP/1.1" 200 -
     425brms-02.brockley.harte-lyne.ca - - [06/Mar/2006 14:13:12] "GET
     426/trac/chrome/common/extlink.gif HTTP/1.1" 200 -
     427
     428}}}
     429
     430Well, everything seems to work.
     431
     43212.  You will now need to customize your trac installation to suite your
     433project needs.  Configuration is carraried out either through the
     434trac-admin command line interface (adding and removing trac users, adding,
     435changing or removing priority and severity codes, adding and removing
     436milestones, etc.) or by directly editing the .trac/conf/trac.ini file. 
     437See [wiki:TracIni]
     438
     439To find out more about trac-admin just run it:
     440
     441
     442{{{
     443#
     444# trac-admin /var/data/trac
     445Trac [/var/data/trac]> help
     446...
     447}}}
     448
     449
     450Or visit [wiki:TracAdmin]
     451
     452More advanced customatization can be accomplished by modifying or
     453replacing the stylesheets in .trac/templates.
     454
     45513.  You WILL, at some point, wish to use trac plugins.  To employ plugins
     456you must install or upgrade setuptools for python.  The easiest way to do
     457this is to obtain ez_setup.py from
     458[http://peak.telecommunity.com/DevCenter/setuptools] and run it as root
     459"#python ez_setup.py".  You can get more information about plugins for
     460trac  at [wiki:TracPlugins].
     461
     462This completes our broadcast day.  We will return later with details about
     463serving trac under apache 2.
     464
     465Regards,
     466Jim
     467
     468***     e-mail is NOT a secure channel     ***
     469James B. Byrne                mailto:ByrneJB.<token>@Harte-Lyne.ca
     470Harte & Lyne Limited          http://www.harte-lyne.ca
     4719 Brockley Drive              vox: +1 905 561 1241
     472Hamilton, Ontario             fax: +1 905 561 0757
     473Canada  L8E 3CE