Upgrade PHP 8.x on FreeBSD

Change log

  • : The guide has been updated for 2026 to have more generic instructions that will apply to different PHP versions.
  • : Initial publication.

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 old, 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,…

You can use brace expansion to simplify 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 modern version you want to install (php83, php84, php85, etc.)

sudo pkg install phpYY phpYY-{bcmath,ctype,curl,dom,exif,extensions,fileinfo,filter,gd,iconv,mbstring,mysqli,opcache,pdo,pdo_mysql,pdo_odbc,pdo_sqlite,pecl-imagick,pecl-json_post,pecl-mcrypt,phar,posix,session,simplexml,sodium,sqlite3,tidy,tokenizer,xml,xmlreader,xmlwriter,zip,zlib}

You may be notified that the packages for the older version will be removed as part of the upgrade process. That’s helpful! Watch for any notices or errors during the upgrade.

If you aren’t told this, or want to be sure the packages are removed:

sudo pkg remove phpXX phpXX-{your list of packages}
sudo pkg remove mod_phpXX

Restart PHP and Apache and then you’re done!

sudo service php-fpm restart
sudo service apache24 restart