Cron always uses the default PHP version that came with the OS and not the one set by Virtualmin. I have 3 versions of PHP installed.
How can I create a cron job that will respect which version of PHP is set in Virtualmin. Here’s a cron I need to run for Magento 2 but it’s being run in PHP 5.4 instead of 5.6…
* * * * * php -c /home/example/etc/php.ini /home/example/public_html/bin/magento cron:run
The way PHP is called from Apache is different from how it’s done on the command line (and cron).
What you’d need to do when calling PHP from cron, is rather than just running the command “php”, which would use which ever PHP versions comes first in your path – you’d want to use the full path to your preferred PHP version.
For additional PHP versions, that’s normally located somewhere in /opt.
Alternatively, rather than calling it using the command line version of PHP, you could instead use a tool like curl or wget to call it via a web request, which would execute it using Apache, and use your configured PHP version.