Spiral Arm Logo

Jono's technical notes

Thursday, October 11, 2007

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

  • http://trac.edgewall.org/
  • http://modpython.org/

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

    • 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  

      make
      sudo make install
      cd ~/apache/2.2.4/bin
      sudo ./apachectrl start
      check there is something sane here http://127.0.0.1/

  2. Install mod_python 3.3.1

    • configure and install
      ./configure --with-apxs=/Users/jono/Applications/apache/2.2.4/bin/apxs
      make
      sudo make install
    • 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
    • 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/bin
        sudo ./apachectrl
        http://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>

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

    • install setuptools

      1. 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
      2. 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

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

      4. install Genshi
        easy_install Genshi

      5. install pysqlite

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

        • if the above seems okay, install it
          easy_install pysqlite

  4. 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.

  5. 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

      1. create projects
        trac-admin project00 initenv
        trac-admin project01 initenv

      2. 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
  6. 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

      1. 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

      2. 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 '*'

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

      4. try and login
        http://127.0.0.1/trac/project0
        http://127.0.0.1/trac/project1

  7. 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

      1. update httpd.conf - change Locaiton from <Location /trac> to <LocationMatch "/.+/"> remembering to also update the closing Location tag to LocationMatch
      2. bounce apache
        sudo ./apachectl stop
        sudo ./apachectl start
  8. 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

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

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

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

Labels: