This is the procedure for upgrading to a minor or major version of the PHP scripting language and its PHP extensions and Apache module on a FreeBSD web server.

PHP release announcements.

New releases of minor and major versions of PHP are announced on the PHP website. You might also get notified about this from other sources, such as the WordPress dashboard. You will want to make sure, that you upgrade to a PHP version, that is supported by your applications.

https://www.php.net/

Determine the installed version of PHP on your FreeBSD server.

You can determine the installed version of PHP by using the PHP command line interface php. If this version is not the version, that is recommended and supported by your applications, then you will want to upgrade.

# php -v

Stop Apache and PHP on FreeBSD web server.

If you are updating PHP on a web server, then you should stop the web server, so users will not experience PHP related error messages or exposed to potential security related information leaks. In the following example, an Apache HTTP server is stopped.

# service apache24 stop

List current version of PHP, PHP extensions and Apache module.

You can have the FreeBSD package manager make a list of all PHP packages, that are currently installed, and then use the list to delete them.

List installed PHP and PHP extensions packages. In this example PHP 7.3 and Apache module extension is installed.

# pkg info | grep php
mod_php73-7.3.27               PHP Scripting Language
php73-7.3.27                   PHP Scripting Language
php73-ctype-7.3.27             The ctype shared extension for php
...

If the list looks fine, then convert it to arguments for the package manager, so you will not have to construct the command manually.

# pkg info | grep php | awk '{printf $1." "}'
mod_php73-7.3.27 php73-7.3.27 php73-ctype-7.3.27 ...

If the shell is csh, then history substitution can be used instead of the general command above. Read more about history substitution on csh in FreeBSD Manual Pages.

# !! | awk '{printf $1." "}'`

Remove old version of PHP, PHP extensions and Apache module with a single command.

You should remove the old version of PHP and PHP extensions for security reasons.

If the list of installed packages from above was sucessful, and the arguments look fine, then delete the packages with the package manager.

# pkg delete `pkg info | grep php | awk '{printf $1." "}'`

If the shell is csh, then history substitution can be used instead of the general command above.

# pkg delete `!!`

Determine the version of PHP to upgrade to.

Determine the version of PHP, that you want to upgrade to. You can see the latest versions at PHP. You can also list the available versions in the package manager.

# pkg search php

Install PHP, extensions and Apache module with one single command.

In this example, PHP, PHP extensions and Apache module is installed with a single command.

# pkg install mod_php74 php74 php74-extensions php74-mysqli php74-openssl php74-pdo_mysql php74-pecl-imagick php74-zip php74-zlib

Note, that the php80-openssl package has been removed from packages. Rerun the command without it. This should not affect the system.

If the shell is csh, then history substitution can be used instead of the general command above.

# pkg install !?delete?:^*:gs/73/74

Start Apache and PHP on FreeBSD web server.

Start the web server and test, that your sites are up and running. If your run WordPress sites, then you might want to check its health check feature. You might also want to look for errors in the system logs and web server logs.

# service apache24 start

About this procedure.

Tested with PHP 7.3 to 7.4 on FreeBSD 12. Tested with PHP 7.4 to 8.0 on FreeBSD 12.3. Tested with PHP 8.0 to 8.3 on FreeBSD 13.2.

More about upgrading on FreeBSD.

How to upgrade and audit packages in FreeBSD and How to upgrade to new minor and major releases of FreeBSD by myself.