When creating a Python script at DreamHost, there are certain rules that must be followed to ensure the file functions properly.
All Python CGI scripts on DreamHost must end with the following extensions:
First line of the Python file
The very first line of the file must be any of the following:
If you've installed a custom version of Python, the first line in your file should point to that location instead. For example, after installing a custom version of Python, run which python. The output will look like this.
[server]$ which python /home/username/opt/python-2.7.17/bin/python
The first line of your file should then look like this.
The file's permissions must be set to 755. You can change this by running the following command via SSH.
[server]$ chmod 755
Make sure to use UNIX style newlines, not Windows.
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"
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).
- Python overview
- SSH overview
- Creating and editing a file via SSH
- How to install a newer version of SWIG
- Installing a custom version of Python 2
- Installing a custom version of Python 3
- Installing and using virtualenv with Python 2
- Installing and using virtualenv with Python 3
- Pyenv: simple Python version management
- Python setuptools