Python Scripts not running in cPanel- Showing code

Python is a high-level programming language. There are users complaining the script shows itself up rather than executing. I am now explaining how to fix this issue.

To test this we must have a test Python code. Here is the hello world test code:

#! /usr/bin/python

print “Content-type: text/html\n\n”

print “Hello world!!”

In cPanel, by-default the Python is located under “/usr/bin/python“. If there was any change, you can check the location by running the following command:

$ whereis python

The python script must be created with the extension “.py”

If you have shell access you can create it by using your favorite file editor (vi, nano etc). You can use the file manager feature, if you have only the cPanel access. Or else the file can be locally created and uploaded using FTP also

Ensure the owner:group is set correctly as the user who is to execute the command Also, it should have executable permission!!

$ chmod +x test.py

Still the script shows up code, the handler must be missing 🙂

Add AddHandler in .htacces file!!

Options +ExecCGI

AddHandler cgi-script .py

You should be good to go now

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.