0

I'm running macOS Catalina and am trying to use WP CLI with MAMP, with iTerm2 and Oh My Zsh as my command line.

However in my localhost directory when I enter wp in the command line, and then press q to exit, I get the following errors:

PHP Notice:  Undefined index: SERVER_NAME in phar:///usr/local/Cellar/wp-cli/2.4.0/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(1197) : eval()'d code on line 5  
Notice: Undefined index: SERVER_NAME in phar:///usr/local/Cellar/wp-cli/2.4.0/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(1197) : eval()'d code on line 5
PHP Warning:  mysqli_real_connect(): (HY000/2002): No such file or directory in /Users/mattpjennings/Desktop/projects/mj/build/mj.net/wp-includes/wp-db.php on line 1626
Warning: mysqli_real_connect(): (HY000/2002): No such file or directory in /Users/mattpjennings/Desktop/projects/mj/build/mj.net/wp-includes/wp-db.php on line 1626

Then when I enter wp plugin list I also get the error below:

Error: Error establishing a database connection.

When I enter wp --info I get:

PHP binary: /usr/local/Cellar/php/7.4.6/bin/php
php.ini used:   /usr/local/etc/php/7.4/php.ini

I already tried adding the line below to ~/.oh-my-zsh/custom/aliases.zsh to change the php or php.ini path when I enter wp --info:

#MAMP Madness export 
PATH=/Applications/MAMP/Library/bin:$PATH 
PHP_VERSION=`ls /Applications/MAMP/bin/php/ | sort -n | tail -1` export 
PATH=/Applications/MAMP/bin/php/${PHP_VERSION}/bin:$PATH

I also tried changing the line below on the wp-config.php file, which didn't work:

define('DB_HOST', '127.0.0.1:8889');

Any help would be appreciated. I really would like to use WP-CLI locally on my Mac.

Your Answer

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

Browse other questions tagged or ask your own question.