Valet+ 500 Error Bricked PHP, pecl extension troubles apcu, apc

Starts with a 500 nginx error, three days ago, when settling down to do a quick update to a wordpress theme.

What have I learned or clarified so far?

  • Valet is a lightweight Mac development environment for Laravel, which is a php framework based on the model–view–controller application approach.
  • Valet+ is a fork of Valet with some added features.
  • Pecl is a library of php extensions, three of which it seems are installed and/or used by Valet+: apc, apcu and geoip.
  • Pecl commands are with the same syntax as pear commands, as they are packaged with the same system.
  • pear is a php classes written in php Whereas pecl is extensions which not written in php and need compiling”
  • Pecl extensions are loaded (on this computer) at /usr/local/lib/php/pecl/somenumber, a path referenced in /usr/local/etc/php/7.1/php.ini: extension_dir = "/usr/local/lib/php/pecl/20160303".
  • APC is a free, open, and robust framework for caching and optimizing PHP intermediate code.
  • APCu – APC User Cache

At one point in troubleshooting, I was getting Error: Calling needs :cxx11 is disabled! There is no replacement. when running Brew commands, after installing henkrehorst/php. I believe this I finally solved by removing all brewed version of php and reinstalling via the Valet+ install steps. I did at one point open up the ruby file for the henkrehorst php brew formula, but didn’t find a solution there.

You may need to brew uninstall --force php@7.1.
And brew uninstall php@7.1 and brew uninstall php@7.2
And/or brew uninstall valet-php@7.1 and brew uninstall valet-php@7.2
And also brew untap henkrehorst/homebrew-php
Then brew cleanup && brew update && brew doctor
Make sure port 80 is available: sudo lsof -i :80
Now run brew tap henkrehorst/php again, then in a NEW TERMINAL type php -v.
Hoping for clean report:

PHP 7.1.23 (cli) (built: Nov 27 2018 16:59:25) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies

Now to be on the safe side composer clearcache.

And then composer global require weprovide/valet-plus.

The valet uninstall may be a thing.

Now I’m getting the ‘Command “fix” is not defined.’ error. The fix is supposed to be this:

composer global remove weprovide/valet-plus && composer global require weprovide/valet-plus

No luck after three tries. Somebody in this issue was able to run valet fix following valet install (with other issues), but I still don’t have valet fix.

Can install the current stable version with

composer global remove weprovide/valet-plus && composer global require weprovide/valet-plus:1.0.27

Now back to the PHP Warning:  Module 'apcu' already loaded in Unknown on line 0 issue.

This temporary fix helps.

Then reach this issue, solved with:

mkdir /usr/local/var/mysql
brew link mysql@5.7 --force
valet fix && valet install

And now: MySql: “Setting password for root user failed.”, noted in #246. A solution:

brew uninstall --force mysql
brew cleanup
brew install mysql 
valet install

Same error. Let’s try this… wait no… Here we go:

mkdir /usr/local/var/mysql
brew link mysql@5.7 --force
valet fix && valet install

Nope. Let’s try reinstalling MySQL this way:

First, uninstall MySQL

brew uninstall mysql
brew uninstall mysql@5.7
brew cleanup
rm -rf /usr/local/var/mysql
rm /usr/local/etc/my.cnf

Now lets install MySQL 5.7

brew install mysql@5.7

You might have to link MySQL since 5.7 is not the latest version available in Homebrew (makes me wonder if this is the root of this issue)

brew link --force mysql@5.7

Run the service

brew services start mysql@5.7

Re-install Valet+

valet fix
valet install

There are a couple of great posts linked here as well.

Will call that the First Successful Valet Install.

Now I can recreate my site, reimport the data and get back to work, hopefully.

wp valet new my-project --project=bedrock

Not so fast, buddy. Error: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES).

UPDATE: The solution may be from wp cli valet:

Prevent this from happening by appending your wp valet commands like such: wp valet new site --dbpass=local_root_password

When you get this error, don’t touch MySQL or Homebrew. It’s fixable by restarting and toggling HTTPS on/off for the site in Valet+. No idea why this works.

SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES)
  • Try valet restart.
  • Try valet unsecure {name} then valet secure {name}.

I am using wp valet and the solution is this:

I didn’t have one set as was able to login to mysql as root without one:

mysql -uroot
# 

So I set one: $(brew --prefix mysql)/bin/mysqladmin -u root password apassword

Not so fast. $(brew --prefix mysql) is pointing to mysql@8.

Completely reinstalling MySql again this way.

Now back to trying to valet install and Problem installing: [UnexpectedValueException] RecursiveDirectoryIterator::__construct(/usr/local/var/mysql): failed to open dir: No such file or directory

Which I fix with here:

mkdir /usr/local/var/mysql
brew link mysql@5.7 --force
valet fix && valet install

Now I go back and redo the “First Successful Valet Install”, above. Now I can run the basic example.test site again. But when I run wp valet new my-project --project=bedrock the Error: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) error is back.

Still $(brew --prefix mysql) is pointing to /usr/local/Cellar/mysql/8.0.16, which doesn’t help.

Ah. “brew --prefix (quoting the man page) “Display the location in the cellar where formula is or would be installed”; since the formula is currently at 5.5.20, that is what it prints. It only matches if you have the latest version installed.” from here.

tree /usr/local/Cellar/mysql@5.7
/usr/local/Cellar/mysql@5.7
└── 5.7.25

So we’ll try: /usr/local/Cellar/mysql@5.7/5.7.25/bin/mysqladmin  -u root password.

Now trying wp valet we get the old error noted above, and when I add a password for mysql, we get a new mysql error:

valet db ls
Password:
PHP Warning:  mysqli::__construct(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: YES) in /Users/philby/.composer/vendor/weprovide/valet-plus/cli/Valet/Mysql.php on line 284
Failed to connect to database

The “solution” seems to be to reinstall mysql!

Do the above dance again, then reinstall wp-cli-valet-command:

wp package install aaemnnosttv/wp-cli-valet-command:^1.0

Mysql works without a password again. valet db ls works again.

Same old error with wp valet new my-project --project=bedrock.

Discourse on Roots.io [here](https://discourse.roots.io/t/anyone-using-valet-with-wp-cli-valet/13600):

FINAL (I hope): Once correct mysql and php are configured, check the file located at ~/.wp-cli/config and it should look something like this:

valet new:
 ## Uncomment or update the relevant lines when necessary to set your own defaults.
 project: bedrock # wp # or bedrock
 # in: # override - defaults to current directory
 version: latest
 # locale:  # use if not English
 db: mysql # or sqlite
 # dbname: # defaults to wp_name
 dbuser: root # or any other local user capable of creating databases (MySQL only)
 dbpass: your_password # enter the appropriate password if necessary (MySQL only)
 dbprefix: wp_
 admin_user: admin
 admin_password: admin
 ## Boolean options can also be configured, too.
 # unsecure: false # set to true to override
 # portable: false # set to true to override

Make sure your mysql password in that file matches the one you ran:

$(brew --prefix mysql)/bin/mysqladmin -u root password your_password

Now generate your site like this:

wp valet new site --dbpass=mysql

At one point, I received this error:

Error: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

Solution was pretty simple, though:

mysql.server start

Returning to Valet+ after an absence. More errors as seems frequently the case. For the following issue.

Starting MySQL
. ERROR! The server quit without updating PID file (/usr/local/var/mysql/jamaaladeen-152.local.pid).

Solution, in this case was:

$ rm -rf /usr/local/var/mysql
$ mysqld --initialize