Skip to main content

Python Script not running on cPanel

Comments

6 comments

  • cPanelMichael
    Hello, The image you provided shows the Python script stored outside of the cgi-bin directory. Can you check to see if it opens correctly when moved within the cgi-bin directory? Thank you.
    0
  • Kent Brockman
    Hello @cPanelMichael sorry for bumping, but I have the exact same issue here. Same Apache handler, same .py script, and it is throwing the same "internal server error" in the browser no matter if I put the script inside cgi-bin or not. Content of test.py:
    #!/usr/bin/python print "Content-type: text/html\n" print "How to run Python scripts in cPanel"
    Content of .htaccess:
    AddHandler cgi-script .py
    test.py has permission 777 And on the terminal:
    # whereis python python: /usr/bin/python2.7-config /usr/bin/python2.7 /usr/bin/python /usr/lib/python2.7 /usr/lib64/python2.7 /etc/python /usr/include/python2.7 /usr/share/man/man1/python.1.gz # /usr/bin/python cgi-bin/test.py Content-type: text/html How to run Python scripts in cPanel
    So, it works in the console but not in the browser. Any advice? Thanks in advance! :)
    0
  • cPanelMichael
    Hello @Kent Brockman,
    AddHandler cgi-script .py

    This entry is not required in the .htaccess file.
    test.py has permission 777

    Permissions should be set to 0755 instead of 0777. Using 0777 permissions will lead to the error message you reported. Let me know if changing the permissions to 0755 helps. Thank you.
    0
  • Kent Brockman
    It worked great! Thanks!!!!
    0
  • cPanelMichael
    Hi @Kent Brockman, I'm glad to see that helped. I've marked this thread as solved. Thank you.
    0
  • ewurama
    Hello, I am having the same problem solved. However, I changed permission of my python main script to 0755 from 0644. But still not working. I have activated a virtual environment for python 3.6 but when i type whereispython, it returns path for python 2.6 Kindly assist
    0

Please sign in to leave a comment.