简体   繁体   English

在 CPANEL 上运行 Python 脚本

[英]Run Python script on CPANEL

I am absolutely not able to figure this out myself, please give me a hint before I go crazy:)我绝对无法自己解决这个问题,请在我 go 发疯之前给我提示:)

My ultimate goal is to execute a python script daily automatically.我的最终目标是每天自动执行一个 python 脚本。 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.我碰巧有一个来自 Bluehost 的虚拟主机,并且了解到我可以使用它。 Then I have checked like the first 4 pages on google trying to follow the many HowTos for this topic, however nothing was successful.然后我检查了谷歌上的前 4 页,试图遵循该主题的许多 HowTos,但是没有成功。 I have the following code:我有以下代码:

#!/usr/bin/python
print "Content-type: text/html\n\n"
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:我将其作为文件添加到我的 public_html/cgi-bin 文件夹中(顺便说一句,cgi-bin 还不存在?),权限为 755。现在,当我打开我的 domain/myscript.py 时,我得到以下信息:

Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request.内部服务器错误 服务器遇到内部错误或配置错误,无法完成您的请求。 Please contact the server administrator at webmaster@wowtierlist.com to inform them of the time this error occurred, and the actions you performed just before this error.请通过 webmaster@wowtierlist.com 联系服务器管理员,告知他们发生此错误的时间以及您在此错误之前执行的操作。 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.此外,在尝试使用 ErrorDocument 处理请求时遇到了 500 Internal Server Error 错误。

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.我没有终端/SSH 访问我的 cpanel(还)所以我无法检查 whereis python,但是 #./usr/bin/python 被 Bluehost 自己显示为示例所以我认为它是正确的。

Any suggestions on what to try?关于尝试什么的任何建议?

Thanks and best regards谢谢和最好的问候

btw the cgi-bin didn't yet exist?顺便说一句,cgi-bin 还不存在?

You will need to check if your apache has support for python (see bottom line notes).您需要检查您的 apache 是否支持 python(见底线注释)。 If you don't have it , you might need module for implementing mod_Python to be installed (ask Bluehost).如果您没有它,您可能需要安装用于实现 mod_Python 的模块(询问 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.如果您已经有“/cgi-bin/”文件夹,您应该有支持,在这种情况下,您需要将 .htaccess 文件添加到 /CGI-BIN 文件夹。

Options +ExecCGI
AddHandler cgi-script .py

There is a way to add Apache Handler (mentioned above as .htaccess) in cPanel.有一种方法可以在 cPanel 中添加 Apache Handler(上面提到的 .htaccess)。 Its under "Advance" as "Apache Handlers".它在“高级”下为“Apache 处理程序”。

The last step is to chmod 755 to yourFile.py to make it executable.最后一步是将 chmod 755 修改为 yourFile.py 以使其可执行。 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.这可以使用 cPanel 中的 FileManager 来完成,找到您的文件并右键单击并选择“更改权限”并将其设置为显示为 755。

NOTE: None of these steps will work unless your apache2 has mode installed to support cgi/py files.注意:除非您的 apache2 安装了支持 cgi/py 文件的模式,否则这些步骤都不会起作用。 I assume you created /cgi-bin/ folder so most likely you have no support for cgi/py installed on your Apache.我假设您创建了 /cgi-bin/ 文件夹,因此很可能您不支持在 Apache 上安装的 cgi/py。 If supported , it will be already there.如果支持,它将已经存在。

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.许多 cpanels 都有应用程序虚拟环境,一旦您的目录设置好/您就可以使用该界面将应用程序配置到虚拟环境中。 in your cPanel use the search bar and type in python.在您的 cPanel 中使用搜索栏并输入 python。

or just scroll down till you see these.或者向下滚动直到看到这些。

在此处输入图片说明

Once there you will setup the file to point to the python app folder which you are creating a virtual enviornment for.在那里,您将设置文件以指向要为其创建虚拟环境的 python 应用程序文件夹。 as well as setting up start scripts etc / install dependencies / run pip all that good stuff.以及设置启动脚本等/安装依赖项/运行 pip 所有这些好东西。

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.长话短说 cpanel 能够运行许多不同类型的脚本和应用程序/但是您需要启动一个虚拟环境。

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.这是您可以与基于 python 的命令交互的文件夹/在给定的程序语言虚拟环境之外,它们在您的网络服务器的其余部分上将没有任何功能。

(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.) (ps,我不是主编码员/一次只学习一天就遇到了您的问题,如果这不是您要问的问题,我想我可能会为您解答抱歉。)

Run All Script in Terminal Cpanel在终端控制面板中运行所有脚本

screen python app.py # Run Background in Script

screen -ls  # Show screen

screen -XS 20411 quit # Quit

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM