This guide provides you with steps to setup and run Python scripts in cPanel.
Python scripts can be run inside ‘public_html‘ or in ‘cgi-bin‘ folder.The cgi-bin folder contains executable CGI scripts. If you are placing the file outside of the cgi-bin folder, ‘.htaccess‘ file should be created additionally to make the script work. For this example we will create the file inside ‘cgi-bin’ folder.
#!/usr/bin/python print "Content-type: text/html\n\n" print "Python is working fine on your server."
INFO: If you would like to run the Python file not in the cgi-bin folder (in public_html or any other directory), it is necessary to add the following code to the .htaccess file in the same directory where the Python script is uploaded:
AddHandler cgi-script .py