This is the procedure for upgrading to a minor or major version of the PHP scripting language on a FreeBSD 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 the 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 potential security related information leaks. In the following example, an Apache HTTP server is stopped.

# service apache24 stop

Remove old version of PHP.

You should remove the old version of PHP and PHP extensions for security reasons. 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 arguments look fine, then delete them with the package manager.

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

Install 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

In this example, the Apache module for PHP is installed together with PHP and PHP extensions.

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

Start the 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

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.

This page was last updated 2022-01-07.