Upgrading PHP on FreeBSD takes only a few minutes.
Start off by listing all of the PHP-related packages on your system, including the PHP extensions you have installed:
pkg query -a %n | grep php8
We’ll use phpXX to represent the older, existing version of PHP on the machine.
In a text editor, take off the leading phpXX- from each extension’s name. Then, put them into a comma-separated format like so:
bcmath,ctype,curl,dom,…
Brace expansion simplifies the package install command. Be sure your shell supports brace expansion, otherwise you’ll get an error.
In the next command, let phpYY be the new version you want to install (php83, php84, php85, etc.)
sudo pkg install phpYY phpYY-{bcmath,ctype,curl,dom,…}
While upgrading, pkg may remove the older versions, which is helpful. Watch for any notices or errors during the upgrade.
Afterwards, ensure that all of the older-version packages are removed, and then clean up and leftover packages:
sudo pkg remove phpXX phpXX-{your list of packages}
sudo pkg remove mod_phpXX
# Clean up any unnecessary leftovers
sudo pkg autoremove
Restart PHP and your webserver and you’re all set!
# Restart PHP-FPM
sudo service php_fpm restart
# Restart your webserver (Change if not Apache)
sudo service apache24 restart