The Artima Developer Community
Sponsored Link

Python Buzz Forum
Getting Zope invited to the Python web framework WSGI party: How to set up Plone and Zope behind...

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Carlos de la Guardia

Posts: 219
Nickname: cguardia
Registered: Jan, 2006

Carlos de la Guardia is an independent web developer in Mexico
Getting Zope invited to the Python web framework WSGI party: How to set up Plone and Zope behind... Posted: Jan 7, 2008 1:30 AM
Reply to this message Reply

This post originated from an RSS feed registered with Python Buzz by Carlos de la Guardia.
Original Post: Getting Zope invited to the Python web framework WSGI party: How to set up Plone and Zope behind...
Feed Title: I blog therefore I am
Feed URL: http://blog.delaguardia.com.mx/feed.atom
Feed Description: A space to put my thoughts into writing.
Latest Python Buzz Posts
Latest Python Buzz Posts by Carlos de la Guardia
Latest Posts From I blog therefore I am

Advertisement

To more and more Python web developers, WSGI, holds the key to the Python web development future. Since there are a number of important web development frameworks and the power of Python makes it really easy to create new ones quickly, interacting with best of breed applications developed in multiple frameworks could soon be the best way to create a new Python web site.

Until relatively recently, Zope and some of its most successful applications, like Plone, ran the risk of missing the WSGI party, but not anymore, now that Repoze is here.

Repoze is a bridge between Zope and WSGI, which has the objectives of both helping Zope developers publish applications using WSGI and, equally important, letting non-Zope web developers use parts of Zope independently.

I recently installed Repoze under WSGI on a test server of mine, and I intend to write about my experiences with it on this blog. This is hopefully the first post of many.

I started with a clean install of Ubuntu Linux 7.10 on a new virtual server. The first step is to install the necessary packages for the correct Python version (Zope currently requires Python 2.4) and also for the Apache server.

Before that, It was necessary to install the required packages for being able to compile and build software using Ubuntu. Be aware that both package installation and Apache module additions usually require root access.

$ apt-get install build-essential

Next, the packages for Python and Apache. Like most packaged Linux distributions, Ubuntu requires a separate install for the development libraries of each piece of software:

$ apt-get install python2.4
$ apt-get install python2.4-dev
$ apt-get install apache2
$ apt-get install apache2-dev

Repoze uses Python's setup tools, so that package is neede as well:

$ apt-get install python-setuptools

Now, the server was ready for mod_wsgi. Since there is no package for this in Ubuntu 7.10, it was necessary to get it directly from the download site:

$ wget http://modwsgi.googlecode.com/files/mod_wsgi-2.0c4.tar.gz
$ tar xzf mod_wsgi-2.0c4.tar.gz $ cd mod_wsgi-2.0c4 $ ./configure --with-python=/usr/bin/python2.4 $ make $ make install

Note that it is necessary to compile mod_wsgi using the same Python you will use to run your web site. Since Zope requires 2.4, the --with-python option was used to point to the newly installed Python.

Once mod_wsgi is intalled, the apache server needs to be told about it. On Apache 2, this is done by adding the load declaration and any configuration directives to the sites-available directory.

The load declaration was put on a file named wsgi.load, which contains only this:

LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so

The configuration directives reside in the file named wsgi.conf, they contain an almost identical configuration to the one shown on the repoze.org site, on the deployment page.

WSGIPythonHome ${sandbox}
WSGIDaemonProcess tmp threads=1 processes=4 maximum-requests=10000 python-path=${sandbox}/lib/python2.4/site-packages
<VirtualHost *:80>
  ServerName my.machine.local
  WSGIScriptAlias /site ${sandbox}/bin/zope2.wsgi
  WSGIProcessGroup tmp
  WSGIPassAuthorization On
  SetEnv HTTP_X_VHM_HOST http://my.machine.local/site
  SetEnv PASTE_CONFIG ${sandbox}/etc/zope2.ini
</VirtualHost>

To really activate this configuration files, another step was required, which is to create soft links for them under the mods-enabled directory of the Apache configuration:

$ cd mods-enabled
$ ln -s ../mods-available/wsgi.load
$ ln -s ../mods-available/wsgi.conf

After this, the server was finally ready for Repoze. The first step was to install repozeproject, which is used to initialize a new Repoze sandbox. As mentioned before, this was done using Python's setup tools:

$ easy_install-2.4 -f http://dist.repoze.org repoze.project

Once repozeproject is ready, it is possible to create any number of repoze applications, which reside in an independent sandbox. This sandbox is really a virtual Python installation based on the same Python used to run the repozeproject command.

For this example, I used repoze.plone, which depends on repoze.zope2 and installs everything that is needed to run Plone (version 3.0.1 as of this writing):

$ repozeproject repoze.plone --path=/home/cguardia/repoze/plone

This command was run using my regular user account and created a plone directory which is actually the Repoze sandbox. The repoze.plone egg that installs this also installs a few sample configuration files, which may be used almost "as is" to run the new site.

To test the installation, first it was needed to add a new user to the Zope site. The command is run from inside the sandbox directory:

$ bin/addzope2user cguardia cg680312

Now the site could be tested using paster:

$ bin/paster serve etc/zope2.ini

Once this was run I had access to the newly installed Zope site at port 8080. I took advantage of this test to add a Plone Site inside, so everything was ready for the WSGI configuration.

The only other requirement for running under mod_wsgi is to install a ZEO server and modify the sandbox's etc/zope.conf file to use a client storage pointing to it. This is very easy, just run (inside the sandbox):

$ bin/mkzeoinst .

This creates runzeo and zeoctl scripts under the bin directory. Since mkzeoinst doesn't delete existing files, I had to make sure that they didn't exist before running it.

Just to save you the trouble of looking it up, here is the section I added to the zope.conf file:

<zodb_db main>
    cache-size 5000
    <zeoclient>
        server localhost:8100
        storage 1
        cache-size 20MB
        name zeostorage
        var $INSTANCE/var
    </zeoclient>
    mount-point /
</zodb_db>

That was it. The site was now ready to work behind Apache and mod_wsgi.

When I tried this I had a lot of problems, because the sample zope2.wsgi script, which is used to run the Zope application process, didn't work at all. After some email and IRC exchanges with ever helpful and friendly Chris McDonough, I ended up fixing it myself and in the process became a commiter to the project (yay!). So, just make sure to run the newly released 0.2.9 version of the repoze.zope2 egg and everything will work ok.

With that out of the way, I just needed to start the ZEO server and, finally, Apache:

$ bin/zeoctl start
$ sudo apache2ctl start

One important thing, since mod_wsgi's daemon mode uses multiple processes, each one needs to execute the whole Zope startup process the first time it is called, so it won't hurt to click a bit through the site when Apache is initially started (or restarted), so that real users don't get these long requests. I hear that mod_wsgi will soon have some kind of preload functionality to deal with this situation better.

There it is. Zope can now run directly behind the Apache server, without need for its own ZServer. As you can see, using Repoze, Zope can now coexist peacefully with other Python frameworks easily using WSGI, but more importantly, it can interact with them. I'll write about some of that magic in another post.


Read: Getting Zope invited to the Python web framework WSGI party: How to set up Plone and Zope behind...

Topic: Python 3000 alpha 1 released! Previous Topic   Next Topic Topic: Finding Python packages

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use