wiki:ThibloPyInstallation

Installing Thiblo under Ubuntu Linux

In this manual, we focus on installing Thiblo on the latest Ubuntu Linux distribution, at the time of this writing, Hardy Heron (8.04).

Get the source

Download the sources under ~/thiblo/trunk/ and ~/thiblo/services/:

mkdir ~/thiblo
cd ~/thiblo
svn co http://dev.thiblo.com/svn/thiblo/thiblopy/ trunk
svn co http://dev.thiblo.com/svn/thiblo/services/ services

Note, that Django web framework will be checked out automatically as an svn external into ~/thiblo/django directory.

Install required packages

sudo apt-get install apache2-mpm-prefork python-yaml libapache2-mod-python \
                     python-json python-urljr python-imaging memcached \
                     python-openid python-setuptools

Install Python memcached client library

wget ftp://ftp.tummy.com/pub/python-memcached/python-memcached-latest.tar.gz
tar xzf python-memcached-latest.tar.gz
cd python-memcached-x.yy
sudo python setup.py install

Install GWT and addons

  1. Install the Java Runtime Environment.
sudo apt-get install sun-java6-jre
  1. Download latest Google Web Toolkit for your OS from  http://code.google.com/webtoolkit/download.html and unpack it to any place. You need only gwt-user.jar and gwt-dev-***.jar files from the distribution, which you need to copy to thiblo/trunk/lib/gwt. (In case you would like to use the so called 'hosted mode' of gwt, you need the whole distribution there, not just the two jars. Most probably you won't.)
cd ~
VERSION=1.4.61
wget http://google-web-toolkit.googlecode.com/files/gwt-linux-${VERSION}.tar.bz2
tar xjf gwt-linux-${VERSION}.tar.bz2
cp gwt-linux-${VERSION}/{gwt-user.jar,gwt-dev-linux.jar} ~/thiblo/trunk/lib/gwt/
  1. Download GWT-Ext library and put gwtext.jar into lib/gwt/addons. Currently tested with version 2.0.2.
cd ~
VERSION=2.0.2
wget http://gwt-ext.googlecode.com/files/gwtext-${VERSION}.zip
unzip -j gwtext-${VERSION}.zip gwtext-${VERSION}/gwtext.jar
mkdir ~/thiblo/trunk/lib/gwt/addons
cp gwtext.jar ~/thiblo/trunk/lib/gwt/addons/

Create a DB

Packages

sudo apt-get install mysql-server python-mysqldb

While installing mysql-server you'll be asked to give a password for the root MySQL user. Do it. After install edit the /root/.my.cnf file like this:

sudo su -
cat > ~/.my.cnf <<'EOF'
[mysqladmin]
user            = root
password        = myrootpw

[client]
user            = root
password        = myrootpw
EOF
chmod 600 ~/.my.cnf

This is needed (the [mysqladmin] part) for the MySQL's system cron jobs. And this way you won't forget the password. :)

Check your MySQL installation:

sudo -H mysqlshow
# +--------------------+
# |     Databases      |
# +--------------------+
# | information_schema |
# | mysql              |
# +--------------------+

Global configuration

We need to do the following changes in the global MySQL config file, /etc/mysql/my.cnf. (Put the definitions anywhere in the appropriate sections.)

[mysqld]
character-set-server = utf8

[mysql]
default-character-set = utf8

Restart mysqld with sudo /etc/init.d/mysql restart

Create user and database

sudo -H mysql <<EOF
CREATE DATABASE thiblo DEFAULT CHARSET = utf8;
GRANT ALL ON thiblo.* TO 'thiblo'@'localhost' IDENTIFIED BY 'thiblopw';
EOF

Change thiblopw to a secret password of your choice. But beware, that it'll be saved in the mysql history file (.mysql_history). If you did not saved the root password in .my.cnf change the command to mysql -u root -p mysql.

Create local domains

Add a virtual host to your /etc/hosts file:

sudo su -
cat >> /etc/hosts <<EOF
127.0.0.1 thiblo.dev www.thiblo.dev thiblo.thiblo.dev
127.0.0.1 alapos.dev www.alapos.dev alapos.thiblo.dev
127.0.0.1 thiblo.dev.master.thiblo.dev
127.0.0.1 alapos.dev.master.alapos.dev
EOF

Configure Thiblo.Py

You can see all default settings in ~/thiblo/trunk/settings.py, however, you should not put developer-specific values there.

Instead, create a file .mysettings.py in the same directory and put your configuration into that.

Example:

TEMPLATE_DEBUG = DEBUG = True

DATABASE_ENGINE = 'mysql'
DATABASE_OPTIONS = {"init_command": "SET storage_engine=InnoDB"}
#DATABASE_PORT = '3306'

DATABASE_NAME = 'thiblo'
DATABASE_USER = 'thiblo'
DATABASE_PASSWORD = 'thiblopw'
DATABASE_HOST = 'localhost'

SECRET_KEY = 'someuniquestring'

CACHE_BACKEND = 'memcached://127.0.0.1:11211/'

BASE_URL = 'http://thiblo.dev'
MASTER_DOMAIN = '.master.thiblo.dev'

Configure Apache

Create a virtual host by copying the Apache settings below to a file named /etc/apache2/sites-available/thiblo:

<VirtualHost *>
  DocumentRoot /home/$USER/thiblo/trunk/
  ServerAlias www.thiblo.dev

  ErrorLog /var/log/apache2/error.log
  LogLevel warn
  CustomLog /var/log/apache2/access.log combined

  Header Set Cache-Control "max-age=0, no-store"

  SetHandler python-program
  PythonHandler django.core.handlers.modpython
  SetEnv DJANGO_SETTINGS_MODULE settings
  PythonDebug On

  # NOTE: we use installation directory here and not its parent.
  PythonPath "['/home/$USER/thiblo/trunk/'] + sys.path"

  <Location "/apps/account/gwt-ext">
    SetHandler None
  </Location>

  <Location "/static">
    SetHandler None
  </Location>

  <Location "/var/files">
    SetHandler None
  </Location>

  <Directory />
    Order Allow,Deny
    Allow from all
  </Directory>
</VirtualHost>

And for cross-domain authentication services (/etc/apache2/sites-available/thiblo-services):

<VirtualHost *>
  DocumentRoot /home/$USER/thiblo/services/master_domain/
  ServerName thiblo.dev.master.thiblo.dev
  ServerAlias *.master.thiblo.dev

  <Directory />
    Order Allow,Deny
    Allow from all
  </Directory>
</VirtualHost>

Enable this server, and also the headers module:

sudo a2ensite thiblo
sudo a2ensite thiblo-services
sudo a2enmod headers

Restart your Apache:

sudo /etc/init.d/apache2 restart

Create database structure and import initial data

To do this move to your installation directory and run:

cd ~/thiblo/trunk
python manage.py syncdb
python manage.py import initial-data --path initial-data
python rungwt.py compile

That's all (almost)

Open your favorite browser (right now, it needs to be firefox or internet explorer) and go look at  http://thiblo.dev!

Note: any time you change any python code, you need to restart the apache server. (It is quite common to be amused by the miracle of restart not always being necessary. The explanation is that separate apache copies have separate compiled copies of the codebase. If you have, say, 20 apache backends running, then they are going to get the requests round-robin, so, for some time, you are going to get newly compiled server side copies handling your request. This miracle though doesn't even last for 3 days...)