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...


... 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

1 Answer 1


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

... to ...

#!/usr/bin/env php
try {
    $dotenv = new Dotenv\Dotenv('../../../../');
    $dotenv->required(['DB_HOST', 'DB_NAME', 'DB_USER', 'DB_PASS']);
} catch (Exception $e) {
    exit('Could not find a .env file.' . $e);

Hope this is of use to other people.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.