CGI support?

I have been digging through Support but have yet to find an answer to this.

Does DH give the user, through access to an Apache httpd.conf file, etc the ability to create CGIs? If so where in the system is this done?

Thank you.

no, yes.

No, you can’t access the httpd.conf file. However cgi scripts work just fine on DH. As long as the file has a .cgi or .pl extension it will be parsed as cgi.

hope that answer your question.

–Matttail - personal website

By default CGI is enabled on all domains. DreamHost uses suexec and this allows you execute CGI from any web directory and not just a cgi-bin directory.

As for “creating CGIs” - with a shell user you can certainly compile code and make executables. Also you can run scripts such as Python, PHP, Perl, and Ruby.

:cool: -//- One-time [color=#6600CC]$50.00 discount[/color] on [color=#0000CC]DreamHost[/color] plans: Use ATROPOS7

So why does the simple following test script not work, no matter what directory I put it in?

import cgitb, cgi, os

print "Content-type: text/html"
print “”

print cgi.escape(os.environ[“REMOTE_ADDR”])

Your shebang! line is wrong. This works:

#!/usr/bin/env python
import cgi, cgitb, os

print "Content-type: text/html"
print “”

print cgi.escape(os.environ[“REMOTE_ADDR”])

see it in action here :wink:


Nope I tried that shebang line too, still getting 500 Internal Server Errors. No matter whether the extension is .cgi, .py and no matter what directory I place the file in.

VERY frustrating.

Did you click the link I provided…it is working there…

What does your error log say (I’m betting “Premature end of script headers”)?

  1. Make sure you have *nix line endings

  2. Make sure you set the script (and the directory it is in) to 755 permissions.


Yep I’m getting that error:

[Thu May 24 18:06:28 2007] [error] [client .*.*.] Premature end of script headers:

  1. Not clear on what *nix line endings should look like. I checked the file and everything looks normal. Maybe editing it with Notepad is a bad idea? The script runs from the command line and I did check it on your site as well.

  2. I changed the directory and file to 755 permissions but I’m still getting the premature end of script headers error…

Thanks for your help, I’m stumped.

Yep, editing it with notepad is a “bad idea”.

Windows (DOS), MAC, and Unix/Linux indicate the end of a line in different ways, and you generally can’t “see” the difference. (if you are interested in the details of this, google has lots of information).

There are a several of ways you can “fix” this, and deal with the problem in the future:

1)Use an editor that lets you work with, and save, files on your computer with *nix style line endings. Then, make sure you ftp the file to your space ion ASCII mode. A great “free” editor for Windows that let’s you work with DOS,*NIX, and MAC line endings, is PSPad. To set the type of line ending for the file, pull-down the “Format” menu and look near the bottom.

2.) Edit the file from the *nix shell with a *nix editor, such as pico, nano, joe, vi, vim, etc. (there are resources explaining this in the DH wiki).

  1. From the shell, run the dos2unix program on the file in question.

Any of those options will result in you having a “good” *nix line-ending type file, and the script should then run fine.


PSPad to the rescue! Thank you!!!

To be clear, if I want to build my main site index from a cgi, the domain name directory must have 755 permissions? Right now it has 0…

Thank you again very much for your help.

Good Deal! I’m really glad you got it to work (and PSPad is a rather nice tool :wink: ).

You may be able to get it to work with tighter restrictions, but not looser! (I’ve never really investigated in most case - DH recommends 755 for directories that run CGI, thanks to the use of suexec). 755 works fine for me.


I have the same trouble.

I made all de sugestions but the page

doesn’t works.

Its with 775 permission (directory and file) and was encoded using vi (ssh).

Some one can help me please ?

I fixed the troble.