Apache, PHP, Python, Numarray, and Matplotlib (sound fun?)

I've had a recurring issue for about 5 days now.

I am running a Fedora Core 2 linux box, which has just been freshly formatted and rebuilt.
I am running Apache as my webserver.
I did clean installs of numarray 1.0 and matplotlib 0.60.2 from source, and they both installed cleanly and completely. The only config I did was in the matplotlib setup.py file, I changed the numerix setting to numarray instead of numeric.
Both packages test out just fine from the command-line python interface.

I am trying to use PHP to call a Python script, which will in turn render some images for display by the PHP web page. The python script runs just fine as a regular user; the plots come out to the proper directory just as they should. But simply calling
  from matplotlib.matlab import *
at the head of the script leads to errors when the script is called by PHP instead. Commenting out this import and any matplotlib function calls allows the PHP script to conclude cleanly (but of course without the desired result).

Here is a snippet from apache's logfile, from one try-through of the php script.

[Fri Jul 16 16:30:28 2004] [error] Numeric import failed... trying numarray.
[Fri Jul 16 16:30:28 2004] [error]
[Fri Jul 16 16:30:30 2004] [error] Traceback (most recent call last):
[Fri Jul 16 16:30:30 2004] [error] File "/httpd/cgi-bin/Webplots/Devel/plotdata.py", line 13, in ?
[Fri Jul 16 16:30:30 2004] [error]
[Fri Jul 16 16:30:30 2004] [error] from matplotlib.matlab import *
[Fri Jul 16 16:30:30 2004] [error] File "/usr/lib/python2.3/site-packages/matplotlib/matlab.py", line 143, in ?
[Fri Jul 16 16:30:30 2004] [error]
[Fri Jul 16 16:30:30 2004] [error] from backends import new_figure_manager, error_msg, \\
[Fri Jul 16 16:30:30 2004] [error] File "/usr/lib/python2.3/site-packages/matplotlib/backends/__init__.py", line 26, in ?
[Fri Jul 16 16:30:30 2004] [error]
[Fri Jul 16 16:30:30 2004] [error] from backend_gtkagg import error_msg, draw_if_interactive, show, new_figure_manager
[Fri Jul 16 16:30:30 2004] [error] File "/usr/lib/python2.3/site-packages/matplotlib/backends/backend_gtkagg.py", line 12, in ?
[Fri Jul 16 16:30:30 2004] [error]
[Fri Jul 16 16:30:30 2004] [error] from backend_gtk import gtk, FigureManagerGTK, FigureCanvasGTK,\\
[Fri Jul 16 16:30:30 2004] [error] File "/usr/lib/python2.3/site-packages/matplotlib/backends/backend_gtk.py", line 21, in ?
[Fri Jul 16 16:30:30 2004] [error]
[Fri Jul 16 16:30:30 2004] [error] import gtk
[Fri Jul 16 16:30:30 2004] [error] File "/usr/src/build/375621-i386/install/usr/lib/python2.3/site-packages/gtk-2.0/gtk/__init__.py", line 43, in ?
[Fri Jul 16 16:30:30 2004] [error] RuntimeError
[Fri Jul 16 16:30:30 2004] [error] :
[Fri Jul 16 16:30:30 2004] [error] could not open display
[Fri Jul 16 16:30:30 2004] [error]
[Fri Jul 16 16:30:30 2004] [error] Premature end of script headers: plotdata.py

I have no idea what that is all about.

I had a problem earlier with the ttf something something cache file that is generated on the first use by each user. Evidently, since Apache doesn't have a home directory, and doesn't have permissions to use /usr/share/matplotlib/ it was getting a permission denial when it tried to create that cache file. I changed the permissions of that directory temporarily to 777, ran the PHP script, and the whole thing got a little bit further before crapping out (as seen above).

Trying to run the script directly as a cgi execution results in identical errors. So the issue is not in PHP.

So If anyone can lead me toward a solution here, I would be much obliged. Also, if anyone can tell me a more elegant fix for the permissions issue above, that would be nice too. I don't like leaving 777 permissions on system files like that.

This package looks like it could be a really great on-the-fly plot generator for web applications, if we can iron out all the config wrinkles. Thanks everyone for your time and patience on this big post. Good Luck!
- Jonathan Hanson
   Department of Physics and Astronomy
   Louisiana State University