0

I need your help. I would like to be able to automate actions that use the php imap extension (email fetching) so I am using a cron job (crontab on mac) but I got an error message when running the script: In Imap.php line 97: Undefined constant ‘OP_READONLY’

I think the error is because the php imap extension is not enabled for php command Line interface. So my question is, what can I do to use my php.ini (used for web server nginx) located in /usr/local/etc/php/7.4.10/. Furthermore I do php -v inside the cronjob task and it seems like the php version used is 7.3.18, so not the version of php I work with on web development. I work on Mac IOS 11 Big Sur (beta version) with nginx, php 7.4.10, php-fpm. Thank you in advance for your help

Regards, Killian

briandev
  • 29
  • 7
  • Use `phpinfo()` in your crontab to see which php.ini files are used. Then you can activate the extension in there. – Markus Zeller Sep 22 '20 at 07:56
  • Instead of using `php -v` you can use `php --ini` to show the loaded configuration files and `php -m` to show the loaded modules. If the ini file or php module you're after is not listed try appending `-c /path/to/target/php.ini`. – Charlie Vieillard Sep 22 '20 at 07:58
  • @CharlieVieillard Thanks for your response. Now the php ini loaded the good one configuration file but the version of php is still 7.3.18. How can I change it please ? – briandev Sep 22 '20 at 08:24
  • You'll need to find out which binary PHP-FPM is using and then use its full path in your crontab. E.g. `/usr/local/Cellar/php/7.4.9/bin` instead of `php`. Location of where your PHP binaries are installed differ depending on OS and/or installation method. Try `locate php-fpm` and additionally filter/search output with `less` and/or `grep`. – Charlie Vieillard Sep 22 '20 at 08:38
  • @KilWeid Did you succeed? – Charlie Vieillard Sep 22 '20 at 11:59
  • @CharlieVieillard finally I use the good one version (7.4) with utilisation of the command "/usr/local/opt/php@7.4/bin/php -q script.php" where the first file path correspond to the path of the version of php that I want to use and "script.php" the file path of the php script that I want to execute for the cron task. – briandev Sep 22 '20 at 14:39
  • Now I search to change the php version used for the command line interface in order to not to be obliged of use this command for every script. If you have an idea of how can I do this, it will be great! @CharlieVieillard – briandev Sep 22 '20 at 14:41
  • @KilWeid You could append `/usr/local/opt/php@7.4/bin` to the `PATH` environment variable in the crontab. See [these answers](https://unix.stackexchange.com/questions/148133/how-to-set-crontab-path-variable). – Charlie Vieillard Sep 22 '20 at 21:08
  • Thanks @CharlieVieillard ! – briandev Sep 23 '20 at 14:51

0 Answers0