Hi there, we are unable to run "api/cron.php" as a cronjob, emails are not being fetched. Hopefully you guys can help us out?
First I want to be clear, fetching emails worked fine with "auto-cron" enabled, so email setup in OsTicket is fine. But I'm unable to run the cronjob in Ubuntu 16.04 from the command line to fetch emails as a ticket with api/cron.php.
Only thing that seemed to solve it was commenting out the line in "/var/www/html/support/api/cron.php" (which is not the proper solution):
//if (!osTicket::is_cli()) die(__('cron.php only supports local cron calls - use http -> api/tasks/cron'));
Our cronjob:
*/1 * * * * www-data /usr/bin/php /var/www/html/support/api/cron.php
According to Ubuntu forums "/usr/bin/php" should run the script as "php-cli" and not "php-cgi"... so that should be correct for the check line i've now commented out. Testing other scripts works fine running it with "/usr/bin/php".
Removing the "www-data" user from the cronjob to run it as root instead didn't help. Also in the OsTicket settings I've switched off "fetch with autocron" as suggested by the docs at https://docs.osticket.com/en/latest/Getting%20Started/POP3-IMAP%20Settings.html
Then tried to run it manually as root and www-data to maybe get some feedback, but nothing happens:
- run as root: sudo /usr/bin/php -f /var/www/html/support/api/cron.php
- run as www-data: sudo -u www-data /usr/bin/php -f /var/www/html/support/api/cron.php
Also enabled debug logs in OsTicket to see if something comes up, but the log remains empty. Also tried to view the apache error log in order to see something, but it doesn't provide any possible error. In the "/var/log/syslog" I can see that the CRON runs fine... So it must have something to do with maybe the PHP version (installed from Ondrei's repo) or the combination with Ubuntu 16.04 or maybe the OsTicket version?
Our details;
- osTicket 1.14.2
- PHP 7.2.31-1+ubuntu16.04.1+deb.sury.org+1 (cli)
- Ubuntu 16.04 LTS
- Apache/2.4.18 (Ubuntu)
- OsTicket web location: /var/www/html/support/
- php7.2-imap installed
Some commands 've used to find the PHP version and path:
:~$ php -v
PHP 7.2.31-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: May 14 2020 08:27:14) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
:~$ which php
/usr/bin/php
:~$ ls -l $(which php)
lrwxrwxrwx 1 root root 21 jun 21 2016 /usr/bin/php -> /etc/alternatives/php
Our problem looks similar to https://forum.osticket.com/d/94293-resolved-please-help-creating-cron-job
Could someone point me in the right direction here please?