php cron 作业命令中的权限被拒绝
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9498298/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Permission denied in cron jobs command
提问by sachin saini
I'm adding a new cronjob using the command command:
我正在使用命令命令添加一个新的 cronjob:
/bin/sh: /home/gbtusyll/public_html/run.php
/bin/sh: /home/gbtusyll/public_html/run.php
But the command doesn't run and i get a mail stating:
但是命令没有运行,我收到一封邮件,说明:
/bin/sh: /home/gbtusyll/public_html/run.php: Permission denied
/bin/sh: /home/gbtusyll/public_html/run.php: 权限被拒绝
What is the problem?
问题是什么?
回答by praseodym
Use php /home/gbtusyll/public_html/run.php
instead to run it as a PHP script instead of a regular shell script.
使用php /home/gbtusyll/public_html/run.php
代替将其作为 PHP 脚本而不是常规 shell 脚本运行。
回答by mkk
try
尝试
chmod +x run.php
also ensure that proper owner is set (i.e. if you are logged as user, if the owner of the file is 'user' - you can do it for example by running ls -la
还要确保设置了正确的所有者(即,如果您以用户身份登录,如果文件的所有者是“用户”-您可以例如通过运行 ls -la
careful: this might be very dangerous on production evironment, however I believe this would solve your development problem. You should read more about permissions later on
小心:这在生产环境中可能非常危险,但是我相信这会解决您的开发问题。您应该稍后阅读有关权限的更多信息
回答by Oldskool
By itself, /bin/sh
can't run php files. The PHP parses does that.
Using /bin/sh
would only work if you give the file execute permissions (+x
) and put #!/usr/bin/php
(or wherever your PHP binary is located) as the first line of the file.
就其本身而言,/bin/sh
无法运行 php 文件。PHP 解析就是这样做的。使用/bin/sh
不仅会工作,如果你给文件执行权限(+x
)和put #!/usr/bin/php
(或是其他地方,你的PHP程序的位置)作为文件的第一行。
Try running /usr/bin/php /home/gbtusyll/public_html/run.php
to use the PHP parser directly on your file. In this scenario, the PHP doesn't have to be executable to run.
尝试运行/usr/bin/php /home/gbtusyll/public_html/run.php
以直接在您的文件上使用 PHP 解析器。在这种情况下,PHP 不必是可执行文件即可运行。