[Zope3-Users] zopeproject generated zope3 app and mod_wsgi

Fernando Correa Neto fcdoth at gmail.com
Thu Aug 28 11:20:00 EDT 2008


Hello there,

First off all, I don't have a blog so I'll be posting it here.

Yesterday I decided to setup a zopeproject generated app with mod_wsgi
and I would like to share my experience.
I am going to skip the part of setting up mod_wsgi with apache because
I think this very well documented.

My environment:

zopeproject generated app sitting at:

    /opt/zope3/app

using python located at:

    /usr/local

buildout-eggs located at:

   /opt/buildout-eggs

For testing purposes, I've added www.foo.com to my /etc/hosts so when
I tried to reach www.foo.com it would resolve to my local machine.

Then we have virtual hosting config (www.foo.com.config in my test case) :

WSGIRestrictStdout Off
WSGIPythonHome /usr/local
WSGIDaemonProcess foo user=fcorrea group=users threads=1
maximum-requests=10000 python-path=/opt/buildout-eggs/

<VirtualHost *:80>
  ServerName www.foo.com
  WSGIScriptAlias /site /opt/zope3/app/bin/zope3.wsgi
  WSGIProcessGroup foo
  WSGIPassAuthorization On
  WSGIReloadMechanism Process
  SetEnv HTTP_X_VHM_HOST http://www.foo.com/site
  SetEnv PASTE_CONFIG /opt/zope3/app/deploy.ini
</VirtualHost>

I created this file based on the one that Carlos de la Guardia created
for grok and did some minor changes to make it work for zope3.

Things I needed to do:

Add the  WSGIRestrictStdout Off directive because for some reason zope
was trying to write something to sys.stdout and mod_wsgi didn't let it
do it.
Modify WSGIPythonHome and pointed to my custom python installation
Modify WSGIDaemonProcess and set python-path to my buildout-eggs directory

It turns out that zopeproject doesn't generate a .wsgi file for you so
you need to create one and it need to look like this:

(zope3.wsgi file based on the one repoze.grok generates)

import os, sys
sys.path.append('/opt/zope3/app/src')
from paste.deploy import loadapp

ini = '/opt/zope3/app/deploy.ini'
application = loadapp('config:%s' % ini)

Well, at this point I thought I was good to go and figured that
something was still missing.
After getting IOErros with zope trying to write logs to
/home/fcorrea/logs/z3.log instead of /opt/zope3/app/log/z3.log, I
rushed to repoze IRC channel and asked for help since they are leading
zope on wsgi stuff.
Chris McDonough again provided some guidance on trying to debug and
asked me to change the user and check if zope would try to write the
logs into that user's home directory and he was right.
That pointed me out that I needed to hardcode the z3.log and Data.fs
paths in my /opt/zope3/app/zope.conf so it would look like this:

   <logfile>
       path /opt/zope3/app/log/z3.log
       formatter zope.exceptions.log.Formatter
   </logfile>

Instead of the defaults generated by zopeproject that looks like this:

   <logfile>
       path log/z3.log
       formatter zope.exceptions.log.Formatter
   </logfile>

After changing the paths I thought I was going to see my nice app's
front page in there but there was one more error in apache's log
related to apidoc.


[Thu Aug 28 12:06:13 2008] [error] [client 127.0.0.2]
ZopeXMLConfigurationError: File "/opt/zope3/app/apidoc.zcml", line
3.2-3.60
[Thu Aug 28 12:06:13 2008] [error] [client 127.0.0.2]
ConfigurationError: ('Invalid value for', 'package', 'ImportError:
Module zope.app has no global preference')

For some reason, apidoc didn't work with my mod_wsgi setup..but heck,
I was going production with the website so who cares about apidoc
right now anyway? So that's what I did. Went back to my
/opt/zope3/app/site.zcml and commented out the apidoc snippet, which
recommends you to turn it off when going production BTW.

So that's it. It is working now and it took me about 1.5h to get it
going and I still don't know if I did it correctly. Does anyone have
any feedback on this? Anyone running plain zope3 with mod_wsgi?
I would be interested in feedback on how to improve this.

Best Regards,
Fernando


More information about the Zope3-users mailing list