Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Short Guide to Running Python Scripts with cPanel

Discussion in 'General Discussion' started by cPanelTristan, Nov 20, 2011.

  1. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,608
    Likes Received:
    32
    Trophy Points:
    238
    Location:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
    In case anyone is new to python and is not certain how to run python scripts under cPanel, I wanted to provide the following short guide. Please note that all mention of username would be the cPanel account username, and all mention of domain.com would be the domain name for that cPanel account.

    1. Start with the following script called hello.py containing this code

    Code:
    #! /usr/bin/python
    
    print "Content-type: text/html\n\n"
    print "<html>Hello world!</html>"
    Normally, cPanel's python is located at /usr/bin/python, but you can run whereis python to ensure it is /usr/bin/python rather than /usr/local/bin/python

    2. Create the file hello.py in /home/username/public_html/cgi-bin with the content noted above

    3. Correct the ownership and file permissions with the following commands:

    Code:
    chown username:username /home/username/public_html/cgi-bin/hello.py
    chmod +x /home/username/public_html/cgi-bin/hello.py
    At that point, the script should work using http://domain.com/cgi-bin/hello.py

    4. If you would like the script to run outside the cgi-bin, place the following content into /home/username/public_html/.htaccess file:

    Code:
    Options +ExecCGI
    AddHandler cgi-script .py
    You could then copy the existing script to /home/username/public_html and have it work there as well.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice