Saturday , 22 October 2016

It's new!!!

How to run Python scripts with cPanel?

Python script showing code itself in browser instead of running!!

Python is a widely used general-purpose, high-level programming language. Its design philosophy emphasizes code readability, and its syntax allows programmers to express concepts in fewer lines of code than would be possible in languages such as C++ or Java. There are some points that you’ve to check before starting-up with your Python script on cPanel server. Here I’m listing some quick points that you should remember before going with Python script.

Hello world!! – A sample Python script to test this!!

Yep, to test this you 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

Create the file with extension “.py” to load the Python script!!

If you have shell access you can create it by using your favorite file editor (vi, nano etc). You can use the filemanager feature, if you have only the cPanel access. And then add the test code into the file. Please change the file ownership to ‘user.user’, after creating it as root user.

chown user.user

user :: Replace with cPanel username. :: The test file you created.

It should have executable permission!!

Yes, the file must has executable permission, so that it can execute the script.

chmod +x

Still I’m in the middle of “Python script showing code itself in browser instead of running”. Ohh, then your apache conf missing the AddHandler for Python.

Don’t forget to add AddHandler in .htacces file!!

Options +ExecCGI
AddHandler cgi-script .py

That’s it!!


1, Managing email notifications in cPanel/WHM
2, How to disable cPHulk Brute Force Protection service in cPanel?

About Arunlal Ashok

Linux Server Administrator. I'm dealing with Linux servers since 2012. I started this blog to share and discuss my ideas with the world. Check My Profile!! in uPwork (oDesk) and let me know if you need any assistance. Thanks!!

Leave a Reply

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