1

This was asked and solved previously, but for Craft 2, see Error Connecting To (MAMP Pro) Database in Console Command. Unable to make it work here.

In short, running console commands like ./craft abc in Craft 3 configured using MAMP gives

Craft isn’t installed yet!    

Exception 'craft\errors\DbConnectException' with message 'Craft CMS can’t connect to the database with the credentials in config/db.php.'

in /Users/stian/dev/site.no/vendor/craftcms/cms/src/db/Connection.php:179

Stack trace:
#0 /Users/stian/dev/site.no/vendor/yiisoft/yii2/db/Connection.php(996): craft\db\Connection->open()
#1 /Users/stian/dev/site.no/vendor/yiisoft/yii2/db/Connection.php(983): yii\db\Connection->getMasterPdo()
#2 /Users/stian/dev/site.no/vendor/yiisoft/yii2/db/mysql/QueryBuilder.php(380): yii\db\Connection->getSlavePdo()
#3 /Users/stian/dev/site.no/vendor/yiisoft/yii2/db/mysql/QueryBuilder.php(399): yii\db\mysql\QueryBuilder->supportsFractionalSeconds()
#4 /Users/stian/dev/site.no/vendor/yiisoft/yii2/db/mysql/QueryBuilder.php(57): yii\db\mysql\QueryBuilder->defaultTimeTypeMap()
#5 /Users/stian/dev/site.no/vendor/craftcms/cms/src/db/mysql/QueryBuilder.php(27): yii\db\mysql\QueryBuilder->init()
#6 /Users/stian/dev/site.no/vendor/yiisoft/yii2/base/BaseObject.php(109): craft\db\mysql\QueryBuilder->init()
#7 /Users/stian/dev/site.no/vendor/yiisoft/yii2/db/QueryBuilder.php(116): yii\base\BaseObject->__construct(Array)
#8 /Users/stian/dev/site.no/vendor/craftcms/cms/src/db/mysql/Schema.php(71): yii\db\QueryBuilder->__construct(Object(craft\db\Connection), Array)
#9 /Users/stian/dev/site.no/vendor/yiisoft/yii2/db/Schema.php(249): craft\db\mysql\Schema->createQueryBuilder()
#10 /Users/stian/dev/site.no/vendor/yiisoft/yii2/db/Connection.php(836): yii\db\Schema->getQueryBuilder()
#11 /Users/stian/dev/site.no/vendor/yiisoft/yii2/db/Command.php(580): yii\db\Connection->getQueryBuilder()
#12 /Users/stian/dev/site.no/vendor/craftcms/cms/src/db/Command.php(142): yii\db\Command->update('{{%queue}}', Array, '[[timeUpdated]]...', Array)
#13 /Users/stian/dev/site.no/vendor/craftcms/cms/src/queue/Queue.php(507): craft\db\Command->update('{{%queue}}', Array, '[[timeUpdated]]...', Array, false)
#14 /Users/stian/dev/site.no/vendor/craftcms/cms/src/queue/Queue.php(449): craft\queue\Queue->_moveExpired()
#15 /Users/stian/dev/site.no/vendor/craftcms/cms/src/queue/Queue.php(95): craft\queue\Queue->reserve()
#16 /Users/stian/dev/site.no/vendor/craftcms/cms/src/queue/Command.php(82): craft\queue\Queue->run()
#17 [internal function]: craft\queue\Command->actionRun()
#18 /Users/stian/dev/site.no/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#19 /Users/stian/dev/site.no/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#20 /Users/stian/dev/site.no/vendor/yiisoft/yii2/console/Controller.php(148): yii\base\Controller->runAction('run', Array)
#21 /Users/stian/dev/site.no/vendor/yiisoft/yii2/base/Module.php(528): yii\console\Controller->runAction('run', Array)
#22 /Users/stian/dev/site.no/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('queue/run', Array)
#23 /Users/stian/dev/site.no/vendor/craftcms/cms/src/console/Application.php(93): yii\console\Application->runAction('queue/run', Array)
#24 /Users/stian/dev/site.no/vendor/yiisoft/yii2/console/Application.php(147): craft\console\Application->runAction('queue/run', Array)
#25 /Users/stian/dev/site.no/vendor/yiisoft/yii2/base/Application.php(386): yii\console\Application->handleRequest(Object(craft\console\Request))
#26 /Users/stian/dev/site.no/craft(22): yii\base\Application->run()
#27 {main}

Ideas?

2

You might not have MAMP's PHP set as your CLI PHP. Have a look at this guide and see if it gets you further

| improve this answer | |
2

I was able to fix this on my local MAMP installation by following the instructions for making MAMP play nicely with Craft in this guide, then executing the command chmod a+x craft from this tutorial.

| improve this answer | |
1

Try with php craft .. instead of ./craft ...

| improve this answer | |

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.