CityHost.UA
Help and support

How to run Python scripts?

Python scripts can be used on hosting servers to work with web applications launched by CGI processes. To use a Python script in CGI mode, you need:

1. In the .htaccess file located [in the root directory of the site], add the following lines:

 Options +ExecCGI AddHandler cgi-script .py

where .py is the extension of the interpreting file.


2. With the help of [file manager] or [ssh access] / [ftp access], set CHMOD access rights to the file - 755

3. In the script itself (in the very first line), explicitly specify the absolute path to the Python interpreter from the instruction .

An example of a script that you can use as a test:

 #!/opt/alt/python37/bin/python3 import cgitb import sys cgitb.enable() print ("Content-Type: text/plain;charset=utf-8") print () print ("Hello World!") print (sys.version)

For the correct operation of Python in cgi mode, the access rights (CHMOD) for the directory from which the script is launched must be - 755 and the rights for the script itself must be set - 755

Error Internal Server Error

or suexec policy violation: see suexec log for more details in [error logs] of the site may indicate the following:

rights 755 on the parent directory or the file itself are not set.

• the script contains invisible BOM symbols , which can be removed in the [SSH] console through the VIM editor with the command : set ff=unix