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).

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.