skip to Main Content

I am absolutely not able to figure this out myself, please give me a hint before I go crazy 🙂

My ultimate goal is to execute a python script daily automatically. I have never done anything like this before and am completely lost. I happen to have a Webhosting from Bluehost and have learned that I might use this. Then I have checked like the first 4 pages on google trying to follow the many HowTos for this topic, however nothing was successful. I have the following code:

#!/usr/bin/python
print "Content-type: text/htmlnn"
print "Python is working fine on your server."

I added this as a file in my public_html/cgi-bin folder (btw the cgi-bin didn’t yet exist?) with permission 755. Now when I open my domain/myscript.py I get the following:

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at [email protected] to inform them of the time this error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error log.
Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

I do not have terminal/SSH access to my cpanel (yet) so I cannot check whereis python, however #!/usr/bin/python is shown as example by Bluehost themselves so I assume it is correct.

Any suggestions on what to try?

Thanks and best regards

3

Answers


  1. btw the cgi-bin didn’t yet exist?

    You will need to check if your apache has support for python (see bottom line notes). If you don’t have it , you might need module for implementing mod_Python to be installed (ask Bluehost). In case you already have had "/cgi-bin/" folder, you should have support and in that case you will need to add .htaccess file to /CGI-BIN folder.

    Options +ExecCGI
    AddHandler cgi-script .py
    

    There is a way to add Apache Handler (mentioned above as .htaccess) in cPanel. Its under "Advance" as "Apache Handlers".

    The last step is to chmod 755 to yourFile.py to make it executable. That can be done using FileManager in cPanel, locate your file and right click and choose "change permissions" and set it to show as 755.

    NOTE: None of these steps will work unless your apache2 has mode installed to support cgi/py files. I assume you created /cgi-bin/ folder so most likely you have no support for cgi/py installed on your Apache. If supported , it will be already there.

    Login or Signup to reply.
  2. a lot of cpanels have apps virtual environment where once your directory is setup / you use the interface to provision the app onto the virtual environment. in your cPanel use the search bar and type in python.

    or just scroll down till you see these.

    enter image description here

    Once there you will setup the file to point to the python app folder which you are creating a virtual enviornment for. as well as setting up start scripts etc / install dependencies / run pip all that good stuff.

    Long story short cpanel has the capability to run many different types of scripts and apps / however you need to start up an virtual enviornment.

    this is the folder you can interact with the python based commands / they will not have any functionality on the rest of your webserver out of that given program languages virtual enviornment.

    (ps im not a master coder / just learning day at a time ran into your question and i think i might have an answer for you sorry if this is not what you were asking.)

    Login or Signup to reply.
  3. Run All Script in Terminal Cpanel

    screen python app.py # Run Background in Script
    
    screen -ls  # Show screen
    
    screen -XS 20411 quit # Quit
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search