FastCGI and scripting languages besides Ruby?

Has anybody tried to write a FastCGI script on a Dreamhost server using a scripting language besides Ruby?

If possible, I’d like to adapt a fairly simple Python-based CGI web app to use FastCGI, but frankly, I don’t know where to begin or if that’s even feasible.

I was thinking the same thing. I found this bit of code on the FastCGI website (there is a section for Python) so I will give it a try.

Herb Lainchbury
Dynamic Solutions Inc.

The answer is YES! It does work. I was able to run the test that is part of the module I pointed to in my last reply… the only problem I am having now is once the app is running… how do I stop it! The test code does not specify how to stop and the techiques I have tried (breaking out of the loop after count>5 for example) have resulted in that script no longer functioning for some reason. If anyone is able to shed some light on this, please do!

Herb Lainchbury
Dynamic Solutions Inc.

From my (somewhat limited) experience with FastCGI, you have to manually kill the running process once it is started. You can find the process ID using ‘ps’ and then use ‘kill’ to kill it.

  • Dallas
  • DreamHost Head Honcho/Founder

Hi Herb,

If you have a chance, could you tell me what you did to get the script to work? I tried to run its test, but I must be doing something completely wrong. Here’s what I did:

  1. Copy to public web dir
  2. Change extension to .fcgi
  3. Make sure it’s executable
  4. Hit it with a web browser

After about a minute, I see an HTTP 500 error. In the web server’s error log, I see:

[Wed Jul 20 09:19:40 2005] [error] [client] FastCGI: comm with (dynamic) server “/home/chompy/” aborted: (first read) idle timeout (60 sec)
[Wed Jul 20 09:19:40 2005] [error] [client] FastCGI: incomplete headers (0 bytes) received from server “/home/chompy/”

Obviously I haven’t even begun to wrap my head around this, but I’m hoping to eventually be able to convert some of my Python CGI scripts to use FastCGI, and then maybe start playing around with the Django framework. But right now I’d be happy just to be able to make a few baby steps.


Hi Jacob,
I assume you have already turned on FastCGI in the DreamHost control panel for that site.

The other thing you might be missing is when you copy .py files to the dreamhost system you have to do a CRLF conversion because your scripts wont run on a *nix box as is. I have a little python script (of course!) that I run to do all of my uploading. If you have no idea what I am talking about let me know and I’ll send you my code.

Other than that, it should be fine. Let us know how it goes.

Herb Lainchbury
Dynamic Solutions Inc.

Hi Herb,

Thanks for the reply. Well, it looks like FastCGI is enabled for my server, and I don’t think CRLFs are a problem, because I can successfully execute the script from a shell prompt.

I wonder what else I could be doing wrong? You just took and ran it unmodified, right?


I am running Python 2.4 so I had to change the first line of the script to point to my Python interpreter. I also had to rename the file to change the extension to .fcgi instead of .cgi. Also, of course make sure your file attributes are right for .cgi execution (i.e. chmod 755).

Herb Lainchbury
Dynamic Solutions Inc.

Drat. I’m using the .fcgi extension and the script’s file attributes are set correctly. The only difference is that I’m using Dreamhost’s Python 2.3 interpreter.


Hmm… have you tried running another script in that same folder… like a hello.cgi (in python of course) just to see if you have python working correctly? I still say check the CRLF thing again. That caused me lots of problems before I finally figured out that I couldn’t just FTP my files up to DH and expect them to run. What I do is upload the file in binary mode but remove all chr(13) before uploading python source files. I think there is a Python command line option so you don’t have to do that but I have never bothered to figure that out becaue I have scripts that do the uploading and converting for me.
i.e. newdata = data.replace(chr(13),’’)
If you want to contact me directly you can go to my website and send me an e-mail. I hate to see another python web scripter suffer! When we sort it out you can post the results here so others can learn from it.

Don’t give up Jacob. It is FAST… worth the effort.

I am trying to hook it up to my DataZoomer python framework now to see how it performs with real apps! I’ll report back.

Herb Lainchbury
Dynamic Solutions Inc.

I had this same error. But then I read the email that dreamhost sent to me about running cgi scripts.

  1. Make sure they have a .cgi or .pl extension. They can be
    in any directory.

  2. Make sure both the script AND THE DIRECTORY THE SCRIPT IS
    IN are owned by ‘skabber’ AND chmod’d to mode 755 (readable,
    writable, and executable by the owner, but only readable and
    executable by group and world) - even if your script’s set-up
    instructions tell you to make it world writable or chmod 777,
    our system requires that permissions be set to mode 755.

Once I did a `chmod 755 fcgi.fcgi’ the script ran.

I have yet to get django working with this yet, but it is a step in the right direction.

First, I want to thank both Herb and skabber for assisting me so far. Unfortunately, I still can’t get that FastCGI script to run!

Here’s what I’ve checked so far:

  • containing directory has permissions set to 755
  • script has permissions set to 755
  • script uses “.fcgi” extension
  • script uses Unix line endings (ran it through the “dos2unix” command)
  • script uses the most recent version of Python on the server (2.3)

I also created a simple “hello world” run-of-the-mill CGI script in Python, and that runs fine:

#!/usr/bin/env python2.3
print "Content-Type: text/plain\n\n"
print “hello world!”

I’m stumped! Obvioiusly I’m still overlooking something, since you both have had some success, though.


I am still very new to this fcgi stuff. All I know is that I have this file in a public dir with the name changed to fcgi.fcgi and chmod 755

I can browse to that file and I get the FCGI TestApp response.

I still have no clue how to hook this up to django or any other wsgi based solution.

I started a django page on the dreamhost wiki.

Hey, thanks a lot!

Unfortunately, I am having the same problem as Jacob… a .cgi python program works fine, but trying to do a .fcgi simply times out!

My server is pizarro… could that have something to do with it?


I am not sure what is going on, but last night all my fcgi scripts were running alright. And today, they are all timing out.


So, now none of us have it working?


I’m still having the problems described above, but, interestingly, I followed your Django instructions from the wiki, and was able to get the Django admin login page to display.

Well if you got the Django login page than fcgi is working. My suggestion for your other fcgi script is to rename it and try again.

I had lots of problems with fcgi scripts that had errors and once there was an error in the script it would not run, even if the error was corrected, unless the script was renamed to something I had not yet used.

For example in my django setup my django.fcgi file is actually called django5.fcgi because it took me 5 tries to get it right.

I think that you may be able to solve the problem that you’re having by running something like ‘ps ax’ from a shell, looking for a process like “python2.3 django.fcgi,” and killing it.

That’s how I’ve been able to move past problems with my Django setup. But I still have no luck with the other fcgi script. It doesn’t show up in the process list, and renaming it definitely doesn’t help, unfortunately.