How to run scripts in Python?

Modified on Thu, 18 Jan 2024 at 11:27 AM

All files specified in the examples should be located in the /domains/YOURDOMAIN/public_html directory.

Minimum code of the running script.

Don't forget to set permissions on the script to 755 (chmod +x


#!/usr/bin/env python
# -*- coding: UTF-8 -*-

import wsgiref.handlers

def application(environ, start_response):
    start_response('200 OK', [('Content-Type''text/plain')])
    return ['Hello World!\n']


Next, create a .htaccess file with the following contents

File: .htaccess

Options -Indexes +ExecCGI
AddHandler cgi-script .py

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !/
RewriteRule ^(.*)$ /$1 [L]

If the script is not located in the root directory of the site, in a subdirectory, then in .htaccess it is necessary to specify the full path to the script. For example:

DirectoryIndex /home/NAMEUSER/domains/YOURDOMAIN/public_html/app/

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article