php artisan and Kernel.php running different PHP versions on Mac OSX
I'm facing a strange issue on my Mac local development. When I run $ php artisan serve and go to phpinfo, it shows PHP 5.6 with the imap version enabled.
When I run phpversion() in my browser I get 5.6.31 and imap works.
However, when I run the same code in Kernel.php it shows 7.1.14 as the PHP version with imap not being enabled.
I'm using homebrew but I uninstalled php 7.
Anyone know of a way to get the kernel to run the same version of PHP that's being used in artisan?
One is the web version, and one is the cli version of php. They both use their own php.ini files, so they can load different extensions and have different settings.
If you view the phpinfo() page from the web browser, it will show which php.ini file is loaded for the web version, and the path to it.
If you run php -i |grep php\.ini from the cli, it will show which php.ini is being loaded for the cli version.
when you uninstalled php 7, perhaps it only uninstalled the web version and left the cli version alone.
What do you mean "the cron". How is the actual cronjob scheduled? The one that is in crontab and runs every minute? Is it specifying a php version to use, or just "php"?
It's possible to have multiple versions and alias them to different names, like "php5" or "php7" to specify a version.
I have it scheduled in /app/console/Kernel.php in Laravel. I'm using MAMP for my mysql server on this machine, running Laravel in parallel. I set my Mac to use MAMP's php 7.1.1 via https://gist.github.com/irazasyed/5987693 but it looks like Laravel still uses php 7.1.4 when it runs anything in Kernel.php.
In my Kernel I have:
protected function schedule(Schedule $schedule)
{
$schedule->call(function ()
{
// my code here which fails to load the correct php version and its extensions
})->everyMinute();
}