Blog, GNU/Linux, IT Security

Installing TRAC with mod_wsgi using virtualenv

This guide is for installing Trac as a user using virtualenv for a isolated Python environment so that the whole installation runs under a specific user.

First of all we need to install needed packages

apt-get install libapache2-mod-wsgi python-virtualenv python-setuptools

Once we have installed the required packages proceed to create the Python environment

mkdir /usr/local/trac
cd /usr/local/trac
virtualenv python

We now have the isolated Python environment locate under /usr/local/trac/python.

To make possible to use easy_install with repositories we need to upgrade easy_install. I use this to install Trac plugins directly from SVN.

/usr/local/trac/python/bin/easy_install -U trunk

We now can install trac 0.12 using the 0.12b1 SVN Tag ( or Trac==0.12b1) or directly from SVN Trunk:


This will download and install the latest trunk version for Trac.

To have webaccess to the Trac projects, we need a .wsgi script, were we define where our local python environment is located:

# Not needed if mod_wsgi >= 3.0
import sys
sys.stdout = sys.stderr

# Load Trac
import trac.web.main
application = trac.web.main.dispatch_request

And finally we need to configure apache. If you want only one Trac project, you should define trac.env to the location of your trac, but if you want multiproject support, you must use trac.env_parent_dir (this is what I used)


    DocumentRoot /usr/local/trac/htdocs
    ErrorLog /var/log/apache2/trac-error.log
    CustomLog /var/log/apache2/trac-access.log combined

    # Trac Auth
        AuthType Basic
        AuthName "Trac"
        AuthUserFile /usr/local/trac/.htpasswd
        Require valid-user
    < /location>

    #Define ProcessGroup with user and group under which it should run
    WSGIDaemonProcess trac user=trac group=trac python-path=/usr/local/trac/python/lib/python2.5/site-packages python-eggs=/usr/local/trac/python/cache
    WSGIScriptAlias / /usr/local/trac/htdocs/trac.wsgi

        WSGIProcessGroup trac
        WSGIApplicationGroup %{GLOBAL}
        SetEnv trac.env_parent_dir /usr/local/trac/projects

We need to create the user and change the permissions for /usr/local/trac for that user trac

adduser --home /usr/local/trac --shell /bin/false --no-create-home trac
chown -R trac:trac /usr/local/trac

If you get an error “ImportError: No module named simplejson” just install it using easy_install

/usr/local/trac/python/bin/easy_install simplejson

Netbeans Performance Switches

I recently have began to use Netbeans because I’m sad that Eclipse is every time slower and it frozes every time when you are doing something to fast.

Netbeans is not perfect, and there are some features that need to be polished (Ex.: SVN Support, Time Tracking like Mylyn), but the PHP/HTML/CSS/JS Support is excellent, in my opinion better than the Eclipse PDF support.

These is my netbeans_default_options for Netbeans for MacOSX (under Windows you can leave out the –laf switch, it’s for changing the look and feel):
Continue reading

Blog, Development

Eclipse Configuration for Web Development

After trying very different IDE and many Eclipse IDE flawors, this is the best configuration I have found, and all the components are free.

First of all we need to download Eclipse Classic from the Eclipse website.

One of the first things we need to do is to change eclipse.ini, we will make it start faster and increase the memory limit


The path to Java VM depends on your installation and system, in windows you must search for “javaw.exe”. Setting the path to Java VM makes that Eclipse stops searching for the Java VM every start, which makes the start faster.

Now we can start installing the required Plugins. In “Help->Install New Software…” we will add the following Update Sites.

  • Aptana –

    Aptana Install

  • Mylyn –

    Mylyn Install

  • Mylyn Extras –

    Mylyn Extra Install

  • SVNKit –

    SVNKit Install

  • EPIC (Perl) – optional, only if you need Perl

    EPIC Install

You have noticed that at each start a Window Asking for Installing Addiontal Features. Now that we can start installing this features. For me the most important are:

  • Aptana PHP

    Aptana PHP Install

  • Aptana PyDev optional, only if you need Python

    Aptana PyDev Install

  • Ajax Libraries You can select all or just the one you need

    Aptana Ajax Libraries Install

After installing all needed plugins we can start with the configuration.

  1. General\Workspace
    • Text file encoding -> UTF-8
    • New text file line delimiter -> Unix
  2. General\Editors\Text Editors
    • Displayed tab width -> 4
    • Insert spaces for tabs -> True
    • Show line number -> True
    • Show print margin -> True
    • Print margin column -> 80
  3. General\Keys
    • Show Whitespace Characters (Text Editing) -> Binding: Ctrl+Alt+Space -> When: Editing Text
  4. Aptana\Editors

    • Formattings -> Insert selected proposal with ‘Tab’ key as well as ‘Enter’ key -> True
    • Tab Insertion -> Use spaces (current width is 4)
  5. Aptana\Editors\PHP
    • Create project file in new PHP project -> False
  6. Aptana\Editors\PHP\Formatting
    • Edit… ->
      • Profile Name -> ZendStandards
      • Control Statemets ->
        • Insert new line before ‘else’ in an ‘if’ statement -> False
        • Insert new line before ‘catch’ in an ‘try’ statement -> False
        • Insert new line before ‘while’ in an ‘do’ statement -> False
        • ‘if else’ – Keep ‘then’ statement on same line -> False
      • Braces ->
        • Method declaration -> Next line
        • Blocks -> Same line
        • Blocks in case statement -> Same line
        • ‘switch’ statement -> Same line
  7. Install/Update\Automatic Updates
    • Automatically find new updates and notify me -> True
  8. Team\SVN – SVN Client
    • SVN Client -> SVN Kit
    • SVN Client -> Use SVN Merge View -> True
  9. Team\SVN\Automatic Properties
    • Add: * -> svn:keywords=Id

I use the Aptana Perspective with this views:

  • Right Top
    • Aptana Standard Views\Project
  • Right Bottom
    • General\Outline
    • Aptana Standard Views\PHP Elements Views
    • Aptana Standard Views\References
  • Bottom
    • General\Tasks
    • Aptana Standard Views\Validation
    • General\Console
    • Team\History
    • Team\SVN Properties
    • EPIC\RegExp only if you installed EPIC
  • Left
    • Tasks\Task List

I like that the Oultine is automatically expanded, so that I have an overview of the file at every moment, but Aptana does not autoexpand the Outline. I use the following workaround:

  • Create a new General Project called “_Monkey”
  • Create a folder called scripts
  • Create a javascript file called autoExpandOutline.js with the following content
     * Menu: EHU > HandlerService (Auto expand outline)
     * Kudos: Ingo Muschenetz & Kevin Lindsey & Steve Daniels
     * License: EPL 1.0
     * Listener: getPartService().addPartListener(this);
     * DOM: http://localhost/com.aptana.ide.scripting
     * DOM:
    function getPartService()
        var workbench =;
        var result = null;
        if (workbench)
            var window = null;
            runOnUIThread(function() {
                window = workbench.getActiveWorkbenchWindow();
                if (window != null)
                    result = window.getPartService();
                    //out.println("result set to " + result);
                    //out.println("window is not defined");
            //out.println("workbench is not defined");
        //out.println("getPartService() is returning " + result);
        return result;
    function partBroughtToTop(part)
    function partClosed(part)
    function partDeactivated(part)
    function partOpened(part)
    function partActivated(part)
      if (part.getEditorInput)
    function partVisible(part)
    function partHidden(part)
    function expandOutline()
        var editor = editors.activeEditor.textEditor;
      catch (e)

Each new project that you create must use this project as reference, and now every time you open a file the Outline will be expanded automatically when you enter into the Editor

Eclipse Layout


Entorno de desarrollo web con Eclipse

Ultimamente estoy mirando de encontrar el mejor entorno de desarollo multiplataforma que me vaya bien para llevar los proyectos de webs. Finalmente el que me ha convencido ha sido Eclipse con los plugins para PHP/HTML/CSS/Javascript y SVN:

  • Aptana: HTML/CSS/Javascript. Update Site:
  • PHPEclipse: PHP. Update Site:
  • Subclipse: SVN. Update Site:

Lo unico que hace falta para instalarse todos los plugins, es bajarse el ultimo Eclipse e ir a “Help->Software Updates->Find and install…” y añadir los “Update Site” de cada uno bajo “Search for new features to install”.

Blog, GNU/Linux

Multiples proyectos con trac y svn usando HTTPS

Voy a explicar como montar el sistema de gestion de proyectos trac y subversion usando https para trabajar con subversion. Yo lo he montado en una debian usando apache2, asi que lo primero que necesitamos es instalar todo lo necesario

apt-get install trac subversion apache2 subversion libapache2-svn libapache2-mod-python2.3

Una vez descargado e instalado creamos el certificado necesario para usar tanto trac y subversion bajo https. Entra en el directorio /etc/apache2/ssl y ejecuta lo siguiente:

openssl genrsa -des3 -out server.key 1024
openssl req -new -key server.key -out server.csr
cp server.key
openssl rsa -in -out server.key
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

Ahora ya tenemos listo los certificados, asi que ahora solo nos queda configurar el apache. Yo he creado un trac.dominio.ext y un svn.dominio.ext para hacer esto, pero esto va a gusto de cada uno. Yo como uso dos subdominios distintos, lo tengo en ficheros separados.

Primero editaremos el trac, asi que creamos el fichero /etc/apache2/sites-available/trac.domain.ext

NameVirtualHost *:443

#Activate SSL
SSLEngine on

SSLCertificateFile    /etc/apache2/ssl/server.crt
SSLCertificateKeyFile /etc/apache2/ssl/server.key

#VirtualHost Servername
ServerName trac.domain.ext
ServerAdmin [email protected]

DocumentRoot /opt/projects/trac


AuthType Basic
AuthName "Trac"
AuthUserFile /opt/projects/.htpasswd
Require valid-user

SetHandler mod_python
PythonHandler trac.web.modpython_frontend
PythonOption TracEnvParentDir /opt/projects/trac/
PythonOption TracUriRoot /

El fichero no necesita demasiada explicacion, simplemente le decimos que active el SSL, que pida autentificacion y cargamos el modulo del trac y le especificamos el path de donde estan todos nuestros proyectos.

Ahora vamos con el fichero /etc/apache2/sites-available/svn.domain.ext

NameVirtualHost *:443

#Activate SSL
SSLEngine on

SSLCertificateFile    /etc/apache2/ssl/server.crt
SSLCertificateKeyFile /etc/apache2/ssl/server.key

#VirtualHost Servername
ServerName svn.domain.ext
ServerAdmin [email protected]

DocumentRoot /opt/projects/svn

DAV svn

AuthType Basic
AuthName "Subversion"
AuthUserFile /opt/projects/.htpasswd
Require valid-user

SVNParentPath /opt/projects/svn
SVNListParentPath on
SVNAutoVersioning On

#Subversion permission file
AuthzSVNAccessFile /opt/projects/svn/.htpasswd

Es importante separar el AuthzSVNAccessFile de ya que sino no listara todos los proyectos en http://svn.domain.ext/ por problemas de permisos.

Ahora que tenemos estos ficheros listos, hay que activar el modulo de ssl en el apache2 y los dos dominios.

vi /etc/apache2/ports.conf

Listen 443

cd /etc/apache2/mods-enabled
ln -s /etc/apache2/mods-available/dav.load .
ln -s /etc/apache2/mods-available/dav_svn.load .
ln -s /etc/apache2/mods-available/mod_python.load .
ln -s /etc/apache2/mods-available/ssl.conf .
ln -s /etc/apache2/mods-available/ssl.load .

cd /etc/apache2/sites-enabled
ln -s /etc/apache2/sites-available/svn.domain.ext 001-svn.domain.ext
ln -s /etc/apache2/sites-available/trac.domain.ext 001-trac.domain.ext

Ahora vamos a crear un proyecto de prueba

mkdir -p /opt/projects/svn
mkdir -p /opt/projects/trac
svnadmin create /opt/projects/svn/NewProject
trac-admin /opt/projects/trac/NewProject initenv
Project Name [My Project]> NewProject
Database connection string [sqlite:db/trac.db]>
Path to repository [/var/svn/test]> /opt/projects/svn/NewProject
Templates directory [/usr/share/trac/templates]>
Creating and Initializing Project
Configuring Project
Installing default wiki pages

Ahora creamos los ficheros de acceso de usuarios.

user = [ [r[w]]]

Por ejemplo, queremos que el user1 pueda leer y escribir, el user2 leer, y anonymous nada (no deberia haber anonymous ya que el htpasswd no los deja pasar, pero siempre viene bien protegerse por si acaso), el fichero quedaria asi

user1 = rw
user2 = r
* =

Ahora ya tenemos todo listo, podemos instalar el modulo TracWebAdmin para que sea mas facil la administracion del trac.