我试图从php创建cronjob,我将它添加到crotanb:
sudo crontab -u www-data -l:
*/1 * * * * /usr/bin/php /var/www/html/service_script/cronTest.php
cronTest.php
<?php
echo 'it works';
include_once('../core/external_init.php');
这是输出:
it works
PHP Warning: include_once(../core/external_init.php): failed to open stream: No such file or directory in /var/www/html/service_script/cronTest.php on line 3
PHP Warning: include_once(): Failed opening '../core/external_init.php' for inclusion (include_path='.:/usr/share/php') in /var/www/html/service_script/cronTest.php on line 3
PHP Fatal error: Uncaught Error: Class 'pluginClassManagement' not found in /var/www/html/service_script/cronTest.php:6
Stack trace:
#0 {main}
thrown in /var/www/html/service_script/cronTest.php on line 6
当我从浏览器运行它时,这个cronTest.php有效。 如果我将/ usr / bin / php更改为/ usr / lib / php,我会收到此错误:
/bin/sh: 1: /usr/lib/php: Permission denied
我真的不知道应该在这里走什么路。
我有php7,我尝试了各种各样的事情来使这项工作,设置权利,使脚本可执行等,但现在我坚持这个,不知道该怎么办
答案 0 :(得分:1)
尝试使用绝对包含路径(例如/var/www/path/to/core/external_init.php)。我很确定,它作为cron运行时使用了错误的工作目录。