trying to make Django work with fastcgi

740 views
Skip to first unread message

soulguide...@gmail.com

unread,
Oct 2, 2007, 5:34:23 AM10/2/07
to Django users
Hi,

I'm new at this - learning as I go, but I can't seem to get Django
running with fastcgi.

A Small Orange, my webhost, doesn't have mod_python support, so I've
been trying to follow a number of different recommendations online to
try and get my site up and running.

I've installed flup, downloaded the django trunk, created a project,
and placed a 'dispatch.fcgi' file in the web root.

If I point my browser to the dispatch.fcgi file, it spins and spins
forever, not even bothering with the kindness of timing out.

If I run the dispatch.fcgi file in the shell, I get the following
error:
># ./dispatch.fcgi
>WSGIServer: missing FastCGI param REQUEST_METHOD required by WSGI!
>WSGIServer: missing FastCGI param SERVER_NAME required by WSGI!
>WSGIServer: missing FastCGI param SERVER_PORT required by WSGI!
>WSGIServer: missing FastCGI param SERVER_PROTOCOL required by WSGI!
>Status: 301 MOVED PERMANENTLY
>content-type: text/html; charset=utf-8
>location: http://localhost:80/

my .htaccess file:
************
AddHandler fastcgi-script .fcgi
RewriteEngine On
RewriteBase /
RewriteRule ^(media/.*)$ - [L]
RewriteRule ^(admin_media/.*)$ - [L]
RewriteRule ^(dispatch\.fcgi/.*)$ - [L]
RewriteRule ^(.*)$ dispatch.fcgi/$1 [L]
************

my dispatch.fcgi file:
************
#!/usr/bin/env python
import sys, os

# Add a custom Python path.
sys.path.insert(0, "/home/soulgt/projects/django/trunk")
sys.path.insert(0, "/home/soulgt/projects/flup/trunk/flup")
sys.path.insert(0, "/home/soulgt/projects")


# Set the DJANGO_SETTINGS_MODULE environment variable.
os.environ['DJANGO_SETTINGS_MODULE'] = "pythonlearning.settings"

from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")
************

I have no idea what's going on and really want to get this off the
ground. Any help would be greatly appreciate - thanks in advance.

Horst Gutmann

unread,
Oct 2, 2007, 5:39:04 AM10/2/07
to django...@googlegroups.com
Have you already looked at the error.log your webhost should normally
provide? The behaviour you indicated normally means, that the process
died or gave output back, that is not really close to an HTTP response
as expected by the webserver.

2007/10/2, soulguide...@gmail.com <soulguide...@gmail.com>:

soulguide...@gmail.com

unread,
Oct 2, 2007, 5:51:03 AM10/2/07
to Django users
The errorlog shows a couple of these:
[Tue Oct 2 05:43:50 2007] [error] [client 76.167.197.252] FastCGI:
incomplete headers (0 bytes) received from server "/home/soulgt/
public_html/dispatch.fcgi"
[Tue Oct 2 05:43:50 2007] [error] [client 76.167.197.252] FastCGI:
comm with (dynamic) server "/home/soulgt/public_html/dispatch.fcgi"
aborted: (first read) idle timeout (240 sec)

many many many of these:
[Tue Oct 2 05:44:11 2007] [warn] FastCGI: (dynamic) server "/home/
soulgt/public_html/dispatch.fcgi" has failed to remain running for 30
seconds given 3 attempts, its restart interval has been backed off to
600 seconds

and a few of these:
[2007-10-02 02:03:32]: error: file has no execute permission: (/home/
soulgt/public_html/dispatch.fcgi)

I hope this helps, as I'm completely lost.

On Oct 2, 2:39 am, "Horst Gutmann" <ze...@zerokspot.com> wrote:
> Have you already looked at the error.log your webhost should normally
> provide? The behaviour you indicated normally means, that the process
> died or gave output back, that is not really close to an HTTP response
> as expected by the webserver.
>

> 2007/10/2, soulguidedtelesc...@gmail.com <soulguidedtelesc...@gmail.com>:

Horst Gutmann

unread,
Oct 2, 2007, 5:54:48 AM10/2/07
to django...@googlegroups.com
2007/10/2, soulguide...@gmail.com <soulguide...@gmail.com>:

>
>
> and a few of these:
> [2007-10-02 02:03:32]: error: file has no execute permission: (/home/
> soulgt/public_html/dispatch.fcgi)
>

Esp. this error looks interesting IMO. Does your host perhaps offer
some information on how they execute the FastCGI processes? Since you
yourself can execute the script in the shell directly (without passing
it explicitly to the python interpreter) it even looks like as if
they're not using something like suExec but execute the script as a
certain user :-/

David Brown

unread,
Oct 2, 2007, 8:30:05 AM10/2/07
to django...@googlegroups.com
I'm actually having the exact same problem (I'm even an ASO customer, as
well). I got rid of the permission errors by changing the permissions on
dispatch.fcgi to 755. However, my .htaccess and dispatch.fcgi are
exactly the same (except that I removed the path stuff, since django and
flup are already in my path). I was able to run manage.py without any
errors, so that pretty much rules out import exceptions and such.

Any ideas what else might be causing this?

Thanks,
David Brown

soulguide...@gmail.com

unread,
Oct 2, 2007, 1:03:09 PM10/2/07
to Django users
I'm exactly there with you, David. Same with the manage.py. I can even
sync up fine with MYSQL.

If anybody has any ideas, I'm more than willing to try pretty much
anything at this point.

On Oct 2, 5:30 am, David Brown <da...@techsamurai.net> wrote:
> I'm actually having the exact same problem (I'm even an ASO customer, as
> well). I got rid of the permission errors by changing the permissions on
> dispatch.fcgi to 755. However, my .htaccess and dispatch.fcgi are
> exactly the same (except that I removed the path stuff, since django and
> flup are already in my path). I was able to run manage.py without any
> errors, so that pretty much rules out import exceptions and such.
>
> Any ideas what else might be causing this?
>
> Thanks,
> David Brown
>

Horst Gutmann

unread,
Oct 3, 2007, 2:19:37 AM10/3/07
to django...@googlegroups.com
Have you already tried it with method=prefork instead of method=threaded?

2007/10/2, soulguide...@gmail.com <soulguide...@gmail.com>:

soulguide...@gmail.com

unread,
Oct 3, 2007, 3:01:41 AM10/3/07
to Django users
I actually got fed up, and nearly resolved to switch either
frameworks(pylons, turbogears) or webhosts(webfaction, dreamhost).

I deleted everything in a fit and started doing some research. I ran
across this in a python installation guide:

"At this point, every tutorial around the web will tell you to use
flup and then there will be pain and hair pulling because you won't
understand why it's not working (unless you ask Allan Saddi to check
your setup, that is. Thank you Allan!).

The solution is to use the supposed to be obsolete fcgi.py script, so
let's install it:

The problem with flup (as found by Allan itself) is that it takes too
long to start and it seems that FastCGI on Dreamhost will wait for a
maximum of 3 seconds. fcgi.py instead is simpler (doesn't do thread
pooling for example) and therefore faster to start. "

What ended up working was simply downloading fcgi.py into my webroot.

Not entirely sure why (and I'm ok with that for now), but it works
like a dream.

I do appreciate your responses regardless. Thank you.

And David, you might want to check out http://www2.jeffcroft.com/blog/2006/may/11/django-dreamhost/.
It's a tutorial for getting started with Django on Dreamhost, but is
excellent and cross-applicable. The only difference is that dreamhost
and ASO handle subdomain differently, so where he writes ~/
django.mydomain.com, substitute ~/www/django (which is automatically
created for you when you create the django.mydomain.com subdomain in
cPanel)

On Oct 2, 11:19 pm, "Horst Gutmann" <ze...@zerokspot.com> wrote:
> Have you already tried it with method=prefork instead of method=threaded?
>

> 2007/10/2, soulguidedtelesc...@gmail.com <soulguidedtelesc...@gmail.com>:

lbolo...@gmail.com

unread,
Oct 6, 2007, 9:34:20 PM10/6/07
to Django users
On Oct 3, 9:01 am, "soulguidedtelesc...@gmail.com"

<soulguidedtelesc...@gmail.com> wrote:
> I actually got fed up, and nearly resolved to switch either
> frameworks(pylons, turbogears) or webhosts(webfaction, dreamhost).
[... big cut...]

Hi all,

i'm hosted at ASmallOrange and can't find a way to make feedjack[1]
work over there. Locally and over the django dev server everything
works smooth so i kinda exclude some gross misconfiguration in my app
settings.

FCGI is enabled from the control panel

I have this setup

~/.bash_profile:
export PATH=$HOME/bin:$HOME/projects/django/bin:$PATH
export PYTHONPATH=$HOME/projects:$PYTHONPATH

~/projects/
fcgi.py
django/ (this is the django source)
newyo/ (this is my app which contains the feedjack app)

~/www/
dispatch.fcgi
.htaccess

dispatch.fcgi contains:
#!/usr/bin/env python
import sys

sys.path += ['/home/lbologni/projects/django/']
sys.path += ['/home/lbologni/projects/']

from fcgi import WSGIServer
from django.core.handlers.wsgi import WSGIHandler

import os

os.environ['DJANGO_SETTINGS_MODULE'] = 'newyo.settings'

WSGIServer(WSGIHandler()).run()

.htaccess contains:


RewriteEngine On
RewriteBase /
RewriteRule ^(media/.*)$ - [L]
RewriteRule ^(admin_media/.*)$ - [L]
RewriteRule ^(dispatch\.fcgi/.*)$ - [L]
RewriteRule ^(.*)$ dispatch.fcgi/$1 [L]

What am i missing?

Thanks,
Lorenzo

--
[1] http://www.feedjack.org/

Reply all
Reply to author
Forward
0 new messages