Real-time Setup: Fully automated domain and web hosting services.

Now Hosting Over 50,000 Domain Names!        

Accredited in Kenya, Rwanda, Nigeria & South Africa.

Kenya's Largest Domain Registar - 2021 KeNIC Report


0722 209 414 | 0733 367 596
info@kenyawebexperts.co.ke

 
 
 

Knowledgebase

Portal Home > Knowledgebase > Advanced > How to run python script Kenya

How to run python script Kenya Print

  • 2

To create and edit Python script in cPanel use the following steps: 

1. Log in to your cPanel:
2. Go to section Files > File Manager




3. You can choose whether you want to run the script in the cgi-bin folder or outside of it. 

The cgi-bin folder contains executable CGI scripts. If the file should be placed out of the cgi-bin folder,.htaccess should be created additionally. 

4. In order to run the Python script in the cgi-bin folder follow the steps: 

  • Go to the cgi-bin folder
  • Create a file with a .py extension, for example nctest.py in the /home/cPuser/public_html/cgi-bindirectory (where cPuser is your actual cPanel username). 

5. In order to create the file, click New File > specify the name of the file with the required extension and click Create New File





6. Change the permission of the file to 0755

NOTE: Files are created with default permissions 0644. The .py file will become executable when the permissions are changed to 0755

7. In order to change the permissions of the file you need to select the file > click Change Permissions >Mark Execute for User, Group, World columns and click Change Permissions





8. Open the file, click Edit and add the code. 

We will add the following script for testing purposes: 

#!/usr/bin/python 

print "Content-type: text/html\n\n"
print "How to run Python scripts in cPanel" 

NOTE: The file should start with the path to the Python scripts that is /usr/bin/python on our servers, but you can run the whereis python command via SSH to check the directory. 

Now the script should work using http://domain.com/cgi-bin/nctest.py 

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 placed: 

Options +ExecCGI 
AddHandler cgi-script .py 

Was this answer helpful?

« Back

Our official partners

The Best Web Hosting Company in Nairobi, Kenya.

Kenya Website Experts Ltd is the Largest Web Hosting Company in Kenya, our core focus is helping and empowering businesses & organizations online. Thousands of customers rely on our domains and web hosting to get their ideas online. We offer everything you need to create an effective & successful online presence backed by expert, personalized customer support. We offer ultra fast, reliable, affordable and secure website hosting services, email hosting, cloud hosting and SSL certificates. We make registration of Kenyan domain names (.co.ke, .or.ke .ac.ke) and international domains (.com, .org, .net) fast, simple, and secure. Our expert team is always on hand to help answer your questions, get you started, and grow your presence online. We deliver on performance, security, reliability and customer service day in, day out, and we’re a trusted partner.

 

Get everything you need for Online Prosperity.