Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ptone/902200 to your computer and use it in GitHub Desktop.
Save ptone/902200 to your computer and use it in GitHub Desktop.

Python 2.6 + Virtualenv + Django 1.1 + Postgres on WebFaction

  1. mkdir -p ~/bin ~/lib/python2.6/site-packages

  2. Configure the environment by putting something like this in your .bashrc and sourcing it:

    export CFLAGS=-I/usr/local/pgsql/include
    export LDFLAGS=-L/usr/local/pgsql/lib
    export LD_LIBRARY_PATH=$HOME/lib:$LD_LIBRARY_PATH
    export PATH=/usr/local/pgsql/bin:$PATH
    export PYTHONPATH=$HOME/lib/python2.6/:$HOME/lib/python2.6/site-packages/
    
    source ~/bin/virtualenvwrapper_bashrc
    source ~/share/git-core/git-completion.bash
    
  3. Install Git:

    curl -O http://kernel.org/pub/software/scm/git/git-1.6.5.3.tar.bz2
    tar -jxf git-1.6.5.3.tar.bz2
    cd git-1.6.5.3
    ./configure && make install
    mv contrib/completion/git-completion.bash ~/share/git-core/
    source ~/share/git-core/git-completion.bash
    
  4. Configure a local Python 2.6 environment:

    easy_install-2.6 --prefix=$HOME distribute
    easy_install-2.6 --prefix=$HOME pip
    pip install --install-option="--prefix $HOME/" virtualenv virtualenvwrapper
    
  5. mkvirtualenv --no-site-packages my_project

  6. Assuming your environment is configured correctly (see above) normal commands like pip install psycopg2 will work at this point.

  7. TODO: Install mod_wsgi for the WebFaction apache using their compilation flags - need to test docs on this but it avoids custom building Apache just to bump the Python version from 2.5 to 2.6.

Memcached

  1. pip install python-memcached

  2. Create a local app following the well-hidden instructions

  3. Create a script like this, taking care to replace <PORT_NUMBER_FROM_APP_PANEL> with the actual number:

    #!/bin/bash
    
    PID_FILE=/home/acdha/webapps/memcached/memcached.pid
    
    if [ -f "$PID_FILE" ]; then
        cat $PID_FILE | xargs --no-run-if-empty kill -0 && exit
    fi
    
    memcached -d -P "$PID_FILE" -l 127.0.0.1 -m 32 -p <PORT_NUMBER_FROM_APP_PANEL>
    
    echo "Started memcached as `cat $PID_FILE`"
    
  4. Create a cron job like this (e.g. using crontab -e) to restart memcached if it crashes or something kills it:

    */5 * * * * /home/acdha/webapps/memcached/memcached_autostart.sh
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment