Ask Your Question
How to run Python scripts in your shared hosting server
Direct to the how-to
- First make sure your hosting supports Python. Now a days almost all shared hosting providers support Python.
- Find your python installation location, this is required for “shebang” line added at the top of your python script. Usually this is /usr/bin/python or /usr/local/bin/python
- Make sure to include two print statements which will print the content-type and an empty line.
- Now put the script in cgi-bin directory inside your root public folder, usually public_html
- Change the permission of the script to 0755
- Try to browse now
Example, hello.py:
#! /usr/bin/python
print ‘Content-type: text/html’
print ”
print ‘Hello, World!’
Now look at the top of hello.py script, you will notice the ‘shebang’ is #! /usr/bin/python.And also the first two print statements
Now its little bit annoying to put all python scripts inside that cgi-bin directory. So heres what you will need to do to run a python script inside any directory…
- Make an empty .htaccss file inside the directory you want to drop your python scripts. (Just open the existing .htaccess file, make sure you have enabled ‘Show Hidden Files’ in cPanel File Manager or in your favorite FTP manager)
- Add the following two lines and save.
Options +ExecCGI
AddHandler cgi-script .py
Tips:
- You will get 500 error if anything goes wrong.
- Make sure to clear your cache, when you modify any settings/content
- And there is always the nice people waiting for you in hosting support section, try them
I hope it helps. Let me know your comment
-
Yourownfree
-
http://askbahar.com Habib Ullah Bahar
-
http://www.gohost.in Hosting
Tags
apache redirection blogging boot Browser directory print download download limit Download Manager download time limit effective search emacs fedora fedora 9 firefox free stuffs Google internet ISO java latex Linux maverick Media miktext mozilla no-www Open Source os PHP picture Picture of the Day python search search techniques social networking Software sulphur sun jdk thesis writing tips Tips n Tricks ubuntu utility vmware player Windows





