FreeBSD – Upgrade PHP 7.4 to 8.0 in one line

This is more of a note to myself but if you want to upgrade PHP 7.4 in one go in FreeBSD, run the following command:

pkg install `pkg query %n-%v | grep php|grep --invert json | sed 's/74/80/; s/-7.*//'`

Note: The above command excludes anything with json, the reason is because the json extension is enabled in PHP 8 by default, so there’s no such package for it. If you have other PHP json packages installed, those will be excluded too.

To check what packages the command will replace, run:

pkg query %n-%v | grep php |grep --invert json | echo `sed 's/74/80/; s/-7.*//'`

If you know what you’re doing you can edit the command for other PHP versions.