Running console (yiic) under MAMP (Windows) I am running Craft 2 under MAMP (PHP 7.0.9) on windows and have a site that works under it. However if I use GIT to cd to the yiic console folder...

/c/mamp/htdocs/website/craft/app/etc/console

... and type ...

php yiic help

... I get an error message ...

Fatal error: Uncaught Error: Class 'Craft\ErrorHandler' not found in C:\MAMP\htdocs\website\craft\app\framework\YiiBase.php:213

... However, if I use PHP 5.6 (the one that I use to run the site - and which therefore has a different php.ini) I get a different message ...

exception 'CDbException' with message 'CDbCommand failed to execute the SQL statement: SQLSTATE[3D000]: Invalid catalog name: 1046 No database selected.

... even though the database settings must be OK as Craft works.

How do I get yiic to work?



PS: I have put some debugging into console\yiic.php and the paths that are getting returned match what I would expect.

I have also looked at Error Connecting To (MAMP Pro) Database in Console Command but the modification it suggests to craft/config/db.php refers to a file that does not exist: mysql.sock
I may have found my own solution. It looks as if Yiic was not picking up the .env file.

The file ... craft\app\etc\console\yiic .. must therefore be changed from ...

#!/usr/bin/env php
&lt;?php
require_once(dirname(__FILE__).'/yiic.php');


... to ...

#!/usr/bin/env php
&lt;?php
require_once('../../../../vendor/autoload.php');
try {
    $dotenv = new Dotenv\Dotenv('../../../../');
    $dotenv-&gt;load();
    $dotenv-&gt;required(['DB_HOST', 'DB_NAME', 'DB_USER', 'DB_PASS']);
} catch (Exception $e) {
    exit('Could not find a .env file.' . $e);
}
require_once(dirname(__FILE__).'/yiic.php');


Hope this is of use to other people.