2

I want to use python for my website.I have a Single Domain Linux hosting from BigRock. And I'hd SSH to my website to check if it has Python Installed so i did >>python -v it turns out python 2.6.6 is already Installed. BigRock support Team asked me to put:

*Options +ExecCGI
**AddHandler cgi-script .py***

in .htaccess file.

But after Doing all this when i try to print Hello using hello.py file It returns 500 Internal Server error.What should I do?

4
  • Is the hello.py file in a directory with CGI privilege? Does it have execute permission? Does it have a valid shebang line? Note that Python 2.6.6 is rather old, and some common 2.7 features will raise an error, eg s = '{}'.format('hello') will raise ValueError. Commented Jun 6, 2016 at 5:57
  • yes, I have set permissions to 755 Commented Jun 6, 2016 at 6:01
  • Is it specifically a Python problem? Eg, can you run a simple Bash script from that directory? Commented Jun 6, 2016 at 6:03
  • Yes i did SSH to cgi-bin Directory Python seems to work fine 'myWeb@cp-in-8 [~/public_html/cgi-bin]# python Python 2.6.6 (r266:84292, Jul 23 2015, 15:22:56) [GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>>' Commented Jun 6, 2016 at 6:09

1 Answer 1

2

Adding Content Type Resolved The Problem.

For Those Who face Same Problem Here is The check List:

Make sure you have Python Installed:

You can SSH your website then type [ python -v ] on terminal it will show you which version of python is Installed.

Make sure you have following Code in .htaccess file. To view .htaccess file go to Legacy File manager Tick on show hidden dot files.

Add following code to it

    Options +ExecCGI
    AddHandler cgi-script .py

Now place all your .py files in cgi-bin folder and set permission to 755

Windows users do not forget to include python location on first line. And type of content on second line:

Location:/home/user/public_html/cgi-bin/test.py

Sample Program:

#!/usr/bin/python

print "Content-type: text/html\n\n";

print "<html><head>";

print "<title>CGI Test</title>";

print "</head><body>";

print "<p>Test page using Python</p>";

print "</body></html>";
Sign up to request clarification or add additional context in comments.

1 Comment

wow i didn't know we can run python on a simple shared hosting account!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.