Categories
Workflow

PHP Monitor and Getting Stuck on an Old Version

I swapped to old PHP 7.4 to update a WordPress project. I then could not switch back to 8.2+. I had the Laravel installer in the global composer dependency, which prevented running composer global update

Go to /Users/mike/.composer/ and temporarily remove the Laravel installer to be able to swap, then can probably put it back afterwards.

Categories
PHP Workflow

Switching local PHP versions with Homebrew

At the time of writing PHP 8.1 is the default, and I have 7.4 and 8.0 installed.

To swap them around link/unlink and then stop and start the appropriate Homebrew service.

Linking changes CLI version; starting the service affects the version Nginx connects to.

You may also want to change the binary that Tinkerwell loads.

Odd Bits

The syntax to link unlink PHP 8.1 (default) are different to the other two. I would not have a clue why.

When you stop a PHP service, sometimes a “fallback” one automatically starts. It might not be the one you want, so you have to stop it and start the one you need.

PHP 8.1

brew unlink php && brew link php

Other versions

brew link --overwrite --force php@7.4
// or 
brew link --overwrite --force php@8.0

Starting the Homebrew service

brew services list
brew services stop php@8.0 
brew services start php
brew services start php@7.4    etc...
Categories
DevOps Workflow

Upgrading to PHP8.0 Locally

Added PHP8.0 with Homebrew. I’m using the shivammathur/homebrew-php tap as recommended in Brent’s post.

Steps

  • brew tap shivammathur/php
  • brew install shivammathur/php/php@8.0
    That seemed to immediately link it. CLI reported 8.0 after that ran.
  • Nginx automatically used it via php-fpm once I restarted Nginx and the PHP service (and Redis)
nginx-restart //(custom alias I have set in .zshrc)
brew services restart php
brew services restart redis

Switching Versions

I think this will just be a matter of brew linking the desired version (if already installed), and restarting php/nginx.

brew link --overwrite --force php@8.0

I’m not totally sure what the old 7.4 is called as far as Brew is concerned. It was the default back when I installed it, so maybe it’s just php , or possibly php@7.4

(A similar thing will probably happen now that PHP 8.1 is the default. I installed PHP 8.0 when it was, so it’s just php . Is it now php@8.0 ?)

Categories
Workflow

Nginx on Homebrew

Feb 2020 – replacing Apache with Nginx to fix broken dev env.

Nginx with PHP-FPM was giving 404 because the script name wasn’t being forwarded to PHP-FPM.

Needed this inside the fast_cgi file. It wasn’t there by default, but some random Googling turned it up 🙁

fastcgi_param   SCRIPT_FILENAME         $document_root$fastcgi_script_name;

Various Paths and Notes

  • Need system Apache to be off. (sudo apachectl stop)
  • May need to (re)start nginx and php-fpm
  • Create new local domains in /usr/local/etc/nginx/servers
  • nginx -t to test config
  • sudo nginx -s reload

Nginx may start as non-sudo/root user and lack permission to bind to :80

In that case I brew services stop nginx, then sudo brew services start nginx.

Paths

  • /usr/local/etc/nginx/ (nginx config)
  • /usr/local/var/www (old default location, I have since changed to my user /Code dir)
  • /usr/local/etc/php/7.4/
  • /usr/local/etc/php/7.4/php-fpm.d/www.conf
Categories
Workflow

Broken MySQL after Homebrew installing Qcachegrind

MySQL died after rebooting after installing Qcachegrind.

I think the problem was brew update doing a ‘prune’ which removed /usr/local/etc/my.cnf.d

I recreated it manually and was able to start MySQL

cd /usr/local/bin
sudo mysql.server start
Categories
PHP Workflow

Local Mac PHP issues

Update March 2019

brew services restart php@7.2

I was trying to change PHP settings, to be able to experiment with Xdebug profiling.

phpinfo() shows that it loads /usr/local/etc/php/7.1/php.ini , which is true, but didn’t seem the case because changes were not taking affect after restarting PHP and Apache.

I was restarting the wrong PHP with brew services restart php71. Even stopping it has no effect.
So that’s not the version that Apache is pointing to. It uses some other instance of the service that I don’t know how to restart without doing the whole computer!

Do this

sudo brew services restart php@7.1
brew services list can also be useful, or even brew services list | grep php