Getting my head round installing plugins from the command line My command line skills are limited but I’m trying to be better. I’ve been using composer successfully for a while to initiate Craft installs, but then subsequently using the Craft web GUI to install plugins.

Today I thought I’d try and use the command line on a fresh local install, which has DB connection details stored in .env as is usual. The host is configured through MAMP Pro on Mac OS Mojave.

I’ve run composer update on my install and it reported there was nothing to update.

I then used the web GUI to install craftcms/contact-form and all went fine, so there is no doubt that my local DB credentials are correct.

Then, in the command line I invoked:

composer require craftcms/contact-form-honeypot


…which ran fine. And then:

./craft install/plugin contact-form-honeypot


…and got: 


  "failed to install contact-form-honeypot: Craft CMS can’t connect to the database with the credentials in config/db.php."


What am I doing wrong?
So this is a MAMP/local dev issue -- run via the CLI, Craft can't connect to the db. Probably it's looking for the wrong mysql.

Check out the MAMP with Composer and MySQL on the Command Line article for details.