2

I have a file:

-rw-r--r-- 1 michal michal 1679 Apr 24 06:55 acx.php

The owner file acx.php is user michal, so I create cron using:

sudo crontab -u michal -e

My cron:

*/10 * * * * php /var/www/html/cron/exchange/acx.php

In log cron I see:

Apr 25 04:10:01 savecoin CRON[9722]: (michal) CMD (php /var/www/html/cron/exchange/acx.php)

I change the permission file acx.php on 777, but it did not help. When I run the cron manually, the data correctly saves to the database. I do not know what else I can change so that cron can write data to the database

I use php7.2, apache2 http server and MySQL database.

michal
  • 161
  • 1
  • 10
  • 2
    Have you tried to specify the path of the php executable ? e.g. /usr/bin/php instead of just php in the cron ? – ponsfrilus Apr 25 '18 at 08:42
  • 1
    Whether the result is the same if you run the job from the root's crontab (sudo crontab -e)? You can redirect the output to a log file, maybe there will find some clue ( */10 * * * * php /var/www/html/cron/exchange/acx.php >> /path-to/log 2>&1). – pa4080 Apr 25 '18 at 08:49
  • The permissions of the script has nothing to do with insertion of records in a database. Does the script update the database correctly when you run it from the command line? – vidarlo Apr 25 '18 at 09:09
  • @Ponsfrilus Change from php to /usr/bin/php it did not help. @pa4080 in new log file I see error: PHP Warning: include_once(../db.php): failed to open stream: No such file or directory in /var/www/html/cron/exchange/acx.php on line 2 PHP Warning: include_once(): Failed opening '../db.php' for inclusion (include_path='.:/usr/share/php') in /var/www/html/cron/exchange/acx.php on line 2 PHP Fatal error: Class 'Database' not found in /var/www/html/cron/exchange/acx.php on line 9, when I run file acx.php using the command php acx.php then the script correctly save data to the database – michal Apr 25 '18 at 09:14
  • 1
    I think the problem are the relative paths in your script. Try this: */10 * * * * cd /var/www/html/cron/exchange/ && php acx.php – pa4080 Apr 25 '18 at 09:16

0 Answers0