aaemnnosttv / wp-cli-valet-command

Harness the power of Laravel Valet for creating fully functional WordPress installs in seconds.
https://aaemnnost.tv/wp-cli-commands/valet/
299 stars 31 forks source link

WP Valet with DBngin on M1 #82

Closed christianmagill closed 3 years ago

christianmagill commented 3 years ago

I'm hoping someone here might be able to assist with getting things setup on my new machine.

I've installed a fresh copy of Valet and DBngin as recommended on Valet's page.

I've installed MySQL through DBngin and updated my path accordingly.

When I try and create a new site through the CLI I receive the following output.

Deprecated: Method ReflectionParameter::getClass() is deprecated in /Users/christianmagill/.wp-cli/packages/vendor/illuminate/container/Container.php on line 811

Deprecated: Method ReflectionParameter::getClass() is deprecated in /Users/christianmagill/.wp-cli/packages/vendor/illuminate/container/Container.php on line 885
Warning: The database was unable to be dropped. Disregard this warning if using sqlite for this site.
Password:
Success: influencebydesign was destroyed.
➜  Sites clear
➜  Sites wp valet new influencebydesign

Deprecated: Method ReflectionParameter::getClass() is deprecated in /Users/christianmagill/.wp-cli/packages/vendor/illuminate/container/Container.php on line 811

Deprecated: Method ReflectionParameter::getClass() is deprecated in /Users/christianmagill/.wp-cli/packages/vendor/illuminate/container/Container.php on line 885
Don't go anywhere, this should only take a second...

Deprecated: Method ReflectionParameter::getClass() is deprecated in /Users/christianmagill/.wp-cli/packages/vendor/illuminate/container/Container.php on line 811

Deprecated: Method ReflectionParameter::getClass() is deprecated in /Users/christianmagill/.wp-cli/packages/vendor/illuminate/container/Container.php on line 885
Error: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

Investigating a little further, I found the following issue and comment, but unfortunately, creating the alias below does not resolve the issue.

https://github.com/TablePlus/DBngin/issues/38#issuecomment-886044172

alias mysql="mysql --socket /tmp/mysql_3306.sock"

Thanks for any help you can provide.

christianmagill commented 3 years ago

I ran across the closed issue on DBngin and decided to just install MySQL through brew for now. I've heard in various comments that WP CLI supports the --socket flag, but I can't find anything in their docs.

ironprogrammer commented 2 years ago

The following works in wp-config.php when using Valet + DBngin (MySQL 8) on Apple Silicon:

define( 'DB_HOST', 'localhost:/tmp/mysql_3306.sock' );

Depending on how many/which databases you have installed, you may need to poke around for the right .sock file, since DBngin can put them on various ports.

I needed this to run phpunit tests in the terminal, so it could connect to the test database (rather than tinker with PHP's config). However, for standard WP installations, I don't have any issues using wp-cli under Valet + DBngin.

(Also see https://gist.github.com/CMCDragonkai/a211f6bf19ae9844ec2763a4438f4495.)

lopadz commented 2 years ago

Thank you @ironprogrammer! I can confirm this also works when using Bedrock + Valet + DBngin on Apple Sillicon. Add this to your .env file:

DB_HOST='localhost:/tmp/mysql_[YOUR_PORT_NUMBER].sock'

Example:
DB_HOST='localhost:/tmp/mysql_3307.sock'