Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

aacook's avatar

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?

0 likes
4 replies
Cronix's avatar

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.

1 like
aacook's avatar

Thank you!

When I run $ php -i |grep php.ini, it's showing /usr/local/php5/lib/php.ini but the cron is still showing 7.1.14. Very weird.

Cronix's avatar

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.

1 like
aacook's avatar

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();
}

Please or to participate in this conversation.