We hope you find this tutorial helpful. In addition to guides like this one, we provide simple cloud infrastructure for developers. Learn more →

How To Install and Use Zope 2 and PostgreSQL on Ubuntu 13.10

PostedMarch 25, 2014 11k views PostgreSQL Ubuntu

Introduction

Zope 2 is a powerful and easy-to-use web-based development framework. This is especially the case when used as a front-end for PostgreSQL.

When used together, high quality database applications with HTML / XML interface can be constructed quickly in a highly scalable, secure, and maintainable fashion.

Compared to the ease-of-use of the resulting system, the installation process is often non-trivial, as there is no single Debian/Ubuntu package that contains and installs all the necessary components. That is the gap that this tutorial aims to fill.

A major challenge to installing Zope + PostgreSQL has been the need to use an adapter that connects between these two. Psycopg2 has been a fast and reliable database adapter but can take a bit of custom trouble-shooting during the installation process from time to time.

The installation procedure documented below is confirmed to work for the versions of Zope, PostgreSQL, PsycopgDA, ZPsycopgDA listed below as examples. If you encounter any difficulties after following these steps, please post a comment and we will all work together to keep the tutorial fresh and relevant.

Install PostgreSQL

Before installing Debian or Ubuntu packages, it is best to change to superuser and perform an update of the package repository:

   sudo su
   apt-get update

in case you want to unzip some of the zope related packages
apt-get install zip

After that, simply install PostgreSQL (9.1.12 is the version in this example):

   apt-get install postgresql

Zope Installation

Install virtualenv, which is helpful to isolate the zope installation from rest of the Python environment on the VPS.

   apt-get install python-virtualenv

make a directory in /home

   mkdir /home/server
   cd /home/server

create a virtual python environment for zope installation

   virtualenv --no-site-packages my_zope
   cd my_zope

activate the virtual environment

   source bin/activate

Install python-dev, which are needed to build Zope from source

   apt-get install python-dev

Find out the newest Zope version number by using a web browser. You don't have to download it, just note the version number for the next step:

   http://download.zope.org/Zope2/index/

Then install Zope (change 2.13.21 to a different version number as appropriate):

   pip install --pre --index-url=http://download.zope.org/Zope2/index/2.13.21/ Zope2

We are ready to make a zope instance. For this example, we will assume that the zope instance directory will be /home/server/zope

   mkzopeinstance

Change into that zope instance directory

   cd /home/server/zope

change ownership to the postgres user; this makes it easier for Zope to access PostgreSQL.

   chown -R postgres:postgres *

change the zope configuration file to run Zope as postgres user (use any editor you like, I am just using vi as example)

   vi etc/zope.conf

find the "effective-user" directive, uncomment, and type in "postgres". The line should look like this when done

   effective-user postgres

Install Psycopg2 and ZPsycopgDA

Install the pre-requisite packages

   apt-get install libpq-dev

Download the Psycopg package and find the most recent version by going to http://www.init.d.org. Change the version number as appropriate:

   wget http://initd.org/psycopg/tarballs/PSYCOPG-2-5/psycopg2-2.5.2.tar.gz

uncompress

   tar xvfz psycopg*gz

install psycopg2

   cd psycopg2*
   python setup.py build
   python setup.py install

Next step is to add ZPsycopgDA to the Zope Products directory. This will link Zope to the Psycopg2 library.

Download the latest ZPsycopgDA (please change the file name asappropriate) from this site: https://pypi.python.org/pypi/ZPsycopgDA/

   https://pypi.python.org/packages/source/Z/ZPsycopgDA/ZPsycopgDA-2.4.6.zip#md5=c76a0e1c8708154dcf07d1362ea8c432

Install by unzipping and then moving the ZPsycopgDA directory into the Zope instance directory (e.g. /home/server/zope/Products)

   unzip ZPsycopgDA*zip
   cd ZPsycopgDA*
   mv ZPsycopgDA /home/server/zope/Products

install the Zope ZSQLMethods product

   easy_install Products.ZSQLMethods

Start Zope

   /home/server/zope/bin/zopectl start

Create Database

Of course, to use the database, it must be created first. To do that, change into the postgres user.

   su postgres
   createdb my_first_database

Now, you can use a web-browser to connect to Zope and use your database as well.

   point your web browser to ip.address.of.server:8080, the Zope management interface will be displayed
   Log-in using the credentials your provided during mkzopeinstance
   select Z Psycopg 2 Database Connection from the drop-down menu
   for connection string, use the following: dbname=my_first_database user=postgres

All done!

If you are new to Zope and PostgreSQL, the next thing to do is create SQL methods to create tables, run queries, etc.

Write SQL by adding Z SQL Method objects (from drop down menu) in the Zope management interface.

Submitted by: Andrew Ho

4 Comments

Creative Commons License