Guidelines for setting up a Python file at DreamHost

When creating a Python script at DreamHost, there are certain rules that must be followed to ensure the file functions properly.

File extensions

All Python CGI scripts on DreamHost must end with the following extensions:

  • .py
  • .cgi
  • .fcgi

First line of the Python file

The very first line of the file must be any of the following:

  • #!/usr/bin/python
  • #!/usr/bin/python2.x
  • #!/usr/bin/env python2.x

File permissions

The file's permissions must be set to 755. You can change this by running the following command via SSH.

[server]$ chmod 755

Line endings

Make sure to use UNIX style newlines, not Windows.

Viewing output

If you want to view printed output from your Python code, you must add this as the first line of output:

print "Content-type: text/html\n\n"

Apache execution

If you don't want .py files to be executed by Apache add the following to your .htaccess file:

RemoveHandler .py

Unix group

At DreamHost, all Python CGI scripts AND their immediate parent directory must have their Unix user and Unix group left set to your domain's Unix user AND that user's DEFAULT Unix group (otherwise you will get an internal server error from Apache's suexec).

See also

Did this article answer your questions?

Article last updated .