You are not logged in Log in Join
You are here: Home » Members » Kedai's space at zope.org » Apache, Zope and FastCGI

Log in
Name

Password

 

Apache, Zope and FastCGI

Apache, Zope and fastCgi

*updated 9/26/00 - added Roug's How-to serve rootfolder from apache *updated 6/7/00 - changed the fastcgi version to the latest
*updated 3/9/00 - added ppetru's tip to use blocking call. also added the need to update FCGIServer.py from cvs
*updated 1/4/00 - added Roug elegent solution to the extra z's. Also added Sam Gendler's solution using fastcgi with unix socket.

I am no Apache, Zope or fastCGI guru. What i'm doing is collecting all information strewn in the mailing list and putting it all together
after successfully installing Apache, Zope, and FastCGI. My environment:-

  • RedHat 6.1 server
  • Intel box
  • python from bin RPMs
  • Zope from src
  • Apache 1.3.9-8 * latest errata, just in case (as informed by Patrick Phalen ).
OK, to the main course.
  1. Get the FastCGI module from www.fastcgi.com. Get the latest tar ball (as of 8 May 00 - mod_fastcgi_2.2.4)
  2. Read the INSTALL that comes with mod_fastcgi. I compiled mine with apxs that ships with apache.
    [root@emedia mine] #cd mod_fastcgi-ver
    
    [root@emedia mod_fastcgi_xxx]# /usr/sbin/apxs -o mod_fastcgi.so -c *.c
    gcc -O2 -m486 -fno-strength-reduce -DLINUX=2 -DUSE_EXPAT -I../lib/expat-lite -fpic -DSHARED_MODULE -I/usr/include/apach
    e  -c fcgi_buf.c
    gcc -O2 -m486 -fno-strength-reduce -DLINUX=2 -DUSE_EXPAT -I../lib/expat-lite -fpic -DSHARED_MODULE -I/usr/include/apach
    e  -c fcgi_config.c
    gcc -O2 -m486 -fno-strength-reduce -DLINUX=2 -DUSE_EXPAT -I../lib/expat-lite -fpic -DSHARED_MODULE -I/usr/include/apach
    e  -c fcgi_pm.c
    gcc -O2 -m486 -fno-strength-reduce -DLINUX=2 -DUSE_EXPAT -I../lib/expat-lite -fpic -DSHARED_MODULE -I/usr/include/apach
    e  -c fcgi_protocol.c
    gcc -O2 -m486 -fno-strength-reduce -DLINUX=2 -DUSE_EXPAT -I../lib/expat-lite -fpic -DSHARED_MODULE -I/usr/include/apach	
    
    [root@emedia httpd]# /usr/sbin/apxs -i -a -n fastcgi mod_fastcgi.so
    cp mod_fastcgi.so modules/mod_fastcgi.so
    chmod 755 modules/mod_fastcgi.so
    [activating module `fastcgi' in /etc/httpd/conf/httpd.conf]	
    
  3. If all goes well, you'd have FastCGI module compiled and installed.
  4. Now you'd need to edit apache httpd.conf. Read the docs (WEBSERVER.txt) that comes with Zope-2.1.1. You can talk to the fastcgi module using unix socket or TCP port. I use TCP port since there were grumblings in the mailing list saying that unix socket does not work reliably. However, my site have yet to receive any major hits, so I can't testify to the reliability of using TCP port. Mail me your experience so that I can include it here.
    ---httpd.conf----
    FastCgiExternalServer /home/httpd/html/z -host localhost:8999 -pass-header Authorization
     
    
    Options ExecCGI
    SetHandler fastcgi-script
    
    ------------------
    

Now all urls pointed to http://myserver.com/z will serve up your Zope contents.
Note that with this setup, the base url becomes http://myserver.com/z

In my case, I want to serve Zope from my root URL. We need Apache Rewrite module for this. Add these rules in your httpd.conf:

------httpd.conf---------
RewriteEngine On
RewriteRule ^/(.*) /z/$1 [PT] #* solution from Roug
RewriteRule ^/(.*) /z/$1 [PT] 
-------------------------
Note:This tip was submitted by "Ron Bickers" . Previously, i managed to get fastcgi running,
but failed to serve Zope off of the root URL. Thanks, Ron!

Also read Roug's How-to serve rootfolder with fastcgi.

Sidenote: With new base URL, reference to absolute_url will return the "z" too. If you are like me, when development of the site is under way,
changing anything will be a headache. A workaround, create a folder "z" in your Zope. And I think that's inheritance working.

Another elegent solution is to add the additional rewrite rule as shown above.

If you have other dirs not in Zope you'd want to serve, just add those before the /(.*) statement. Tip: the log files are your best friend!

You will need to restart zope and apache for the changes to take effect.

To use fastcgi with unix socket, try what Sam Gendler has done.

--quote sam---
I got it working with Virtual hosts, so that even the root directory of the virtual
host is directed to zope.

The config was as follows:


ServerName www.impossible.com
DocumentRoot /home/httpd/impossible
ServerAlias impossible.com *.impossible.com
ServerAdmin admin@impossible.com
ErrorLog /home/httpd/log/www.impossible.com-error_log
CustomLog /home/httpd/log/www.impossible.com-access_log common
FastCgiExternalServer /home/httpd/impossible \
-socket impossible.soc \
-pass-header Authorization

Options ExecCGI
SetHandler fastcgi-script



I did have to make the file pointed to by FastCgiExternalServer be a file.  When I
tried to make it a directory, I was able to access zope, but lots of things didn't
work correctly (could not access manage screen, any files in subdirectories, etc). As
soon as I made it a file, and gave it 0777 permissions, everything worked
flawlessly.  Notice that DocumentRoot and FastCgiExternalServer are the same.  I
think this is necessary if you want to have the entire site sent to zope.  I also had
to sart zope with -F /tmp/fcgi/socketfile.soc, since the mod_fcgi automatically looks
in /tmp/fcgi.  You can change that behaviour with a config directive, but I don't
know what it is.

--sam
--end quote---

Problems, experiences, and fixes

  • Quoting sam " Every once in a while, the document has http headers visible at the top, almost as though apache put headers on the document and then zope put headers on as well. I didn't look last time, but next time, I will check and see which one looks to have put headers on last (the visible ones). A simple reload fixed the problem. --sam "
  • Quoting me " Zope crashing once in a while, with no apparent reasons. This on RH6.1, apache 1.3.9-8, PIII. But on Apache 1.3.6, RH5.2, P133, I never had that yet."

Apache with fastcgi sometimes could not handle requests, prompting error 505. To stop or minimize this error, update FCGIServer.py which sits in $ZOPEHOME/ZServer. Get the latest version (v 1.7 as of 3/9/00) from the cvs. Download it, rename the original FCGIServer.py and replace it with the latest version. Restart Zope for the change to take effect.

Also, use blocking call to fastcgi by adding -appConnTimeout 0 (see below)

---
FastCgiExternalServer /home/httpd/html/z -host localhost:8999 -pass-header Authorization -appConnTimeout 0
---

However, i still experience "(111)Connection refused: FastCGI: failed to connect to server "/home/httpd/html/z": connect() failed " and " FastCGI: incomplete headers (0 bytes) received from server "/home/httpd/html/z"" with all the updates i did. Anybody know why?

During my short experience with Zope, mod_pcgi and mod_fastcgi, I would say mod_pcgi provides more statbility, while mod_fastcgi gives you speed.
I think when mod_fastcgi and zope's support for it matures, mod_fastcgi will be as stable as mod_pcgi.

As always, if you find errors, do point them to me. Also, mail me your experiences, be it good or bad, and your solutions.

Credits go to the mailing list and the zope community. Other useful docs