Honza
Honza

Reputation: 323

cronjob execution php error

Im trying to create cronjob from php, I added it to 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');

And this is the output:

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

This cronTest.php works when I run it from browser. If I change /usr/bin/php to /usr/lib/php I get this error instead:

/bin/sh: 1: /usr/lib/php: Permission denied

I dont really know what path should be here.

I have php7, i tried all kinds of thing to make this work, setting rights, make the script executable etc but now Im stuck on this and dont know what to do anymore

Upvotes: 0

Views: 119

Answers (1)

DBX12
DBX12

Reputation: 2041

Try it with an absolute include path (like /var/www/path/to/core/external_init.php). I'm pretty sure, it uses the wrong working directory when run as cron.

Upvotes: 1

Related Questions