Install Trac with OpenID on Ubuntu Linux 12.04

Here's my short note on installing Trac on Ubuntu 12.04 + authOpenID
Trac is an enhanced wiki and issue tracking system for software development projects. Trac uses a minimalistic approach to web-based software project management (
  1. install packages:
    sudo apt-get install python python-babel trac trac-authopenid trac-git
  2. create trac environment. My environment is like this:
    1. /trac   (Trac Parent Directory)
    2. /trac/myproject    (my project directory
    sudo mkdir /trac
    sudo mkdir /trac/myproject
    sudo chown -R your-username:users /trac   #set it to belong to you, for easier setup for now
  3. initial Trac project
    trac-admin /trac/myproject initenv
  4. Edit myproject's trac config
    1. Go to /trac/myproject/conf/
    2. use your prefer editor (gedit,kate,vi) to open up "trac.ini"
    3. add this at the bottom for authOpenID
      trac.web.auth.* = disabled
      authopenid.* = enabled
    4. Enable file logging(save to /trac/myproject/log/trac.log) by changing "log_type = none" to "log_type = file"
    5. set Header Logo, under "[header_logo]" edit the config like this:
      alt = My Project
      height = 200
      link = 
      src = site/images/logo.png
      width = 800
      "site/" means your local "htdocs" (/trac/myproject/htdocs). Meaning it will search for "logo.png" under /trac/myproject/htdocs/images/logo.png
    6. set other settings if you would like
  5. Try running it on standalone first, to see if the configuration works. Use command: "tracd -p 8888 /trac/myproject" .
    1. If it is working you can browse to localhost:8888 and it should be running smoothly.
    2. don't forget to login with OpenID, by clicking "OpenID Login" on top-right corner. So we can capture the OpenID username and use it later
    3. you can stop the server on the command line terminal by pressing Ctrl-C
  6. Setting OpenID user. Since we turned on logging to file, and we tried logged in with OpenID user.
    1. see the log(using vi,tail,kate,gedit) on log file located at /trac/myproject/log/trac.log
    2. What you are looking for is something like this
      2012-08-30 04:39:28,131 Trac[session] DEBUG: Retrieving session for ID u'anidear'
      The OpenID user name is in u'xxxxxxx'. In this case, it is "anidear".
    3. Using trac-admin command to grant permission to this user if he is an admin
      trac-admin /trac/myproject permission add anidear TRAC_ADMIN
      where as "anidear" is my username from previous step.
  7. Update Trac settings using command
    trac-admin /trac/myproject upgrade
  8. (Optional) You may need to remove all wiki pages. It can be done by this script 
    # extract the page list from trac (this filter matches only CamelCase words or numbers,
    # it will blow if there are pages which does not fit into this scheme)
    for site in `trac-admin /trac/myproject wiki list | sed -e 's/\([a-zA-Z0-9]*\).*/\1/'`
        # and remove every single page
        trac-admin /trac/myproject wiki remove $site
  9. Change permission so Apache can read/write to it.
    But I'm single user on this machine and I want to modify the file sometimes. So I'll just set the group for "www-data" (Apache group) just enough for Apache to read the file. Otherwise, you can set both user and group to belong to Apache buy using "www-data:www-data" for it.
    sudo chown -R :www-data /trac
    sudo chmod -R 775 /trac
  10. Setting Trac to works with Apache2:
    1. go to /etc/apache2/sites-available and create a file named "trac-site" (need root privilege) by using any editor
    2. put this in the file:
      NameVirtualHost *:9999
      <VirtualHost *:9999>
          ServerName trac.local
          <Location />
              SetHandler mod_python
              PythonInterpreter main_interpreter
              PythonHandler trac.web.modpython_frontend
      #        PythonOption TracEnv /trac/myproject
              PythonOption TracEnvParentDir /trac
              PythonOption TracUriRoot /
              PythonOption TracLocale en_US.UTF8
              PythonOption PYTHON_EGG_CACHE /tmp
              Order allow,deny
              Allow from all
      #    <Location /login>
      #        AuthType Basic
      #        AuthName "myproject"
      #        AuthUserFile /trac/.htpasswd
      #        Require valid-user
      #    </Location>
          ErrorLog /var/log/apache2/trac_error.log
          # Possible values include: debug, info, notice, warn, error, crit,
          # alert, emerg.
          LogLevel warn
          CustomLog /var/log/apache2/trac_access.log combined
      1. Listen set to accept any IP that comes to server with port 9999 (you can limit to use within your machine by changing to
      2. NameVirtualHost and VirtualHost are accepting any IP on port 9999 (again, to make it private change * to
      3. "<Location />" is for serving Trac as the root of URL "http://localhost:9999/"
      4. "PythonOption TracEnv" is for using single project. If you want to use only single project, uncomment this line
      5. "PythonOption TracEnvParentDir" points to parent directory of projects
      6. "PythonOption TracUriRoot" is the URL that we want to use when request for Trac main page. "/" means to "http://localhost:9999/"
      7. I comment out normal Trac authentication using htpasswd because we already change to use OpenID authentication.
      8. "ErrorLog","CustomLog","LogLevel" are settings for keep logging on Trac and location to save the logs to
    3. use command "sudo a2en trac-site" to enable this site on Apache2
    4. restart Apache2 using "sudo service apache2 restart"

No comments:

Post a Comment