running a cherrypy application behind apache using mod_python

64 views
Skip to first unread message

Gowri

unread,
Jan 6, 2008, 10:24:27 PM1/6/08
to cherrypy-users
Hi,

I'm new to Python and am especially almost ignorant about web
programming. I'm not even sure if there is a way to write a web
application in python and deploy it on apache using mod_python alone
without using say wsgi or cherrypy or other HTTP frameworks. Could
anyone please tell me if this is possible and if yes, how?

For now, after reading up some articles I get the impression that I
would be better off using a HTTP framework. I decided to try Cherrypy
and was following instructions on http://cherrypy.org/wiki/DeployTemplate

I don't want to run the Cherrypy builtin server but only want to run
apache. Now on the above mentioned page they say that:

If needed, use no server at all by importing this module and then
calling serverless(). This allows you to ask the Engine for a Request
object and manipulate it directly (even step through the request
process with pdb if you like).

Could someone please tell me how this is done?

Also. I'm mostly a Java programmer and have no idea how I should write
a module which accepts GET and POST requests and have these methods
called when a particular URL is invoked. I did find some example code
but I'm not sure if any changes need to be made to httpd.conf to say
something to the effect of 'call this method on invocation of this
URL'.

I apologize for asking too many questions in a single post.

Regards,
Gowri

Tim Roberts

unread,
Jan 11, 2008, 1:35:25 PM1/11/08
to cherryp...@googlegroups.com
Gowri wrote:
> I'm new to Python and am especially almost ignorant about web
> programming. I'm not even sure if there is a way to write a web
> application in python and deploy it on apache using mod_python alone
> without using say wsgi or cherrypy or other HTTP frameworks. Could
> anyone please tell me if this is possible and if yes, how?
>

It is possible, but it is terribly inconvenient. A mod_python program
has to talk directly to Apache APIs. It's not like the CGI model, where
you read parameters from stdin, and then send headers and HTML to
stdout. Also remember that it's a pain in the rear during development,
because you may need to restart Apache every time you change your script.

mod_python is somewhat interesting technology, but it is only a solution
for a very narrow range of problems. I've done dozens of Python-based
web sites, and I've never used it.

Don't discard the possibility of straight CGI, especially in early
development. It is clearly the easiest to configure, and requires no
special permissions on remote hosting services. And unless you are
handling several hundred requests a minute, the performance is entirely
adequate.

> For now, after reading up some articles I get the impression that I
> would be better off using a HTTP framework. I decided to try Cherrypy
> and was following instructions on http://cherrypy.org/wiki/DeployTemplate
>
> I don't want to run the Cherrypy builtin server but only want to run
> apache.

Why? The CherryPy builtin server is quite capable, and by using the
Apache proxy method, your users will not be able to tell the
difference. What problems do you fear in using the builtin server?

> Also. I'm mostly a Java programmer and have no idea how I should write
> a module which accepts GET and POST requests and have these methods
> called when a particular URL is invoked. I did find some example code
> but I'm not sure if any changes need to be made to httpd.conf to say
> something to the effect of 'call this method on invocation of this
> URL'.
>

The CherryPy tutorials should answer much of this. You shouldn't really
need any changes in httpd.conf. Using the proxy method, I use an
.htaccess file in a given directory that routes all requests within that
directory to my CherryPy app. The CherryPy machinery then searches for
a handler for the next part of the URL using its normal dispatch mechanism.

--
Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.

Robert Brewer

unread,
Jan 11, 2008, 2:16:50 PM1/11/08
to cherryp...@googlegroups.com
Tim, I officially owe you a drink of your choice. Thanks for your
consistently timely and accurate help on this list.


Robert Brewer
fuma...@aminus.org

Reply all
Reply to author
Forward
0 new messages