How to install trac 0.11 on OS X ( 10.4.10)

The following are notes on how to install and configure trac on OS X with multiple projects with a dedicated user to maintain the trac installation. These notes have been derived from several sources and are primarily so I can reproduce this at a later date without thinking, they are, unsurprisingly

You'll need the following

  • sudo / root access
  • internet access
  • python 2.3.5
  • sqlite3

You will need to download

  1. Install Apache 2.2.4

  2. Follow Richard's instructions, see step 6 for an overview
    ./configure --prefix=/Users/jono/Applications/apache/2.2.4 --enable-mods-shared=most --enable-ssl --with-mpm=worker --without-berkeley-db --enable-proxy  makesudo make installcd ~/apache/2.2.4/binsudo ./apachectrl start
    check there is something sane here http://127.0.0.1/

  3. Install mod_python 3.3.1

  4. configure and install
    ./configure --with-apxs=/Users/jono/Applications/apache/2.2.4/bin/apxsmakesudo  make install
  5. tell apache about it

    add
    LoadModule python_module /Users/jono/Applications/apache/2.2.4/modules/mod_python.so
    to
    /Users/jono/Applications/apache/2.2.4/conf/httpd.conf
  6. test apache is talking to python

    1. edit httpd.conf add

      <Location /mpinfo>
      SetHandler mod_python
      PythonHandler mod_python.testhandler
      </Location>

    2. restart apache and see what we get

      cd ~/apache/2.2.4/binsudo ./apachectrlhttp://127.0.0.1/mpinfo

      you should get a table showing various System information about apache, python and the request headers, including who the process is running as. In our case it is daemon - make a note of this you'll need it later.

    3. clean up

      remove the following from httpd.conf

      <Location /mpinfo>
      SetHandler mod_python
      PythonHandler mod_python.testhandler
      </Location>

  7. Install python modules required by the latest version of trac ( 0.11)

  8. install setuptools

  9. this will need to be done as root so you have write permissions to /System/Library/Frameworks/Python.framework/Versions/2.3/bin
    sudo python ez_setup.py
  10. link it to a bin directory in your path - This should be a single line!

    sudo ln -s /System/Library/Frameworks/Python.framework/Versions/2.3/bin/easy_install easy_install

  11. test it, type eas and you should get tab completion, well, assuming you are using bash.

  12. install Genshi
    easy_install Genshi

  13. install pysqlite

  14. make sure easy_install is going to install the correct version,it should be 2.3.2 or above
    easy_install -n pysqlite

  15. if the above seems okay, install it
    easy_install pysqlite

  • Install trac

    This is some what more convoluted than it needs to be, once edgewall release a complete version (0.11) of trac, this will be


    easy_install trac

    However at present this installs 10.4, which is not what we want, so it is worth trying easy_install -n trac to see if it is going to install 0.11, until then, there is :

    • check out the latest code from svn, in my case this was revision 6049.
      svn co http://svn.edgewall.org/repos/trac/trunk trac

  • install trac
    sudo python ./setup.py install

  • link the trac binaries to a bin directory in your path.
    sudo ln -s /System/Library/Frameworks/Python.framework/Versions/2.3/bin/ trac-admin trac-admin
    sudo ln -s /System/Library/Frameworks/Python.framework/Versions/2.3/bin/ tracd tracd

  • If you want to be sure trac is installed and working before continuing ( probably a good idea ) check the Observations notes below.

  • set up trac user and environment

  • create a trac user - see my previous post

  • add them to the daemon group - or whatever user apache is running at
    sudo nicl / -merge /groups/daemon users daemon

  • as the trac user create the projects and set the correct permissions

  • create projects
    trac-admin project00 initenv
    trac-admin project01 initenv

  • set the permissions on the trac projects
    chown -R :daemon project00
    chown -R :daemon project01
    chmod -R g+rw project00
    chmod -R g+rw project01
  • Configure apache to talk to trac via mod_python

    • add the following to httpd.conf

      <Location /trac>
      SetHandler mod_python
      PythonInterpreter main_interpreter
      PythonHandler trac.web.modpython_frontend
      PythonOption TracEnvParentDir /Users/trac
      PythonOption TracUriRoot /trac
      </Location>

      <LocationMatch "/trac/[^/]+/login">
      AuthType Basic
      AuthName "Trac"
      AuthUserFile /Users/trac/.htpasswd
      Require valid-user
      </LocationMatch>

    • as the trac user populate .htpasswd
      htpasswd -c /Users/trac/.htpasswd jono

  • as the trac user configure trac permissions

  • add an administrative user for the projects
    trac-admin /Users/trac/project00 permission add jono TRAC_ADMIN
    trac-admin /Users/trac/project01 permission add jono TRAC_ADMIN

  • remove anonymous and authenticated permissions from all projects, this is needed so users can not log into projects others than there own and is probably just a good idea ;)
    trac-admin /Users/trac/project00 permission remove anonymous '*'
    trac-admin /Users/trac/project00 permission remove authenticated '*'
    trac-admin /Users/trac/project11 permission remove anonymous '*'
    trac-admin /Users/trac/project11 permission remove authenticated '*'

  • bounce apache
    sudo ./apachectl stop
    sudo ./apachectl start

  • try and login
    http://127.0.0.1/trac/project0
    http://127.0.0.1/trac/project1

  • restrict access to projects - currently every entry into .htpasswd has access to all projects, as an authenicated user, which would allow users from one project to browse and edit the wiki or another - not an ideal situation, so we do the following

  • remove ability to see project listing - what people can't see they can't try and access

  • update httpd.conf - change Locaiton from <Location /trac> to <LocationMatch "/.+/"> remembering to also update the closing Location tag to LocationMatch
  • bounce apache
    sudo ./apachectl stop
    sudo ./apachectl start
  • Finally

    Things to do:

    • get svn access working
    • consider https
    • consider using digest rather than basic athenication
    • virtual hosts

    Links

    Observations


    1. install using the default locations for python, installing with user specific locations will cause a great deal of pain, if you know what you are doing with PYTHONPATH, you will probably be okay, then again, you probably aren't going to be reading this either :)

    2. if you ignored me and tried installing setuptools without root access you will have noticed the binary failed to install and now you are wondering how to get it installed.
      sudo python ez_setup.py -U setuptools

    3. restarting apache,there are notes on either the trac or mod_python site about this, it would appear that sudo ./apachectl restartdoesn’t always work, this is usually when you are tired and it has been working all day, save yourself pain just use.
      sudo ./apachectl stop
      sudo ./apachectl start
    4. if trac isn’t playing you may want to make sure it is installed correctly, try the following

      1. create a dummy project
        trac-admin testTrac initenv

    5. start the trac daemon
      tracd --port 8000 /Users/jono/Documents/trac/testTrac

    6. point a browser to
      http://localhost:8000/testTrac

    7. if it all looks okay, you can delete this now