Can't update latest version of PHP using MacPorts

480 Views Asked by At

I have tried using MacPorts to update to the latest version of PHP. After typing sudo port install php and installing all the necessary packages, when I type php --version in the terminal, I still get:

PHP 7.3.29 (cli) (built: Aug 15 2021 23:10:16) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.29, Copyright (c) 1998-2018 Zend Technologies

Why does my computer still have an outdated version of PHP instead of PHP 8?

1

There are 1 best solutions below

0
neverpanic On

The php port in MacPorts is a shim, it only installs the /opt/local/share/doc/php/README file and depends on (currently) php82. Click one of the Files links on https://ports.macports.org/port/php/details/ to see that.

What gets run when you type php --version in your shell depends on the symlink /opt/local/bin/php, but that symlink is managed by the port select mechanism explained in the port-select(1) manpage:

port select provides a mechanism to choose from different implementations of a common tool or port. Selecting one of the options makes it the primary version or implementation, e.g. the one to be run by default when you do not explicitly select a version or implementation on the command line.

Note that port select is only for your convenience as user. It does not, for example, affect which compiler MacPorts uses when it compiles software, or against which copy of MySQL a port builds. If there is a user-visible choice, it is usually offered as a variant on the port. If the port select mechanism affects how a port builds, that should be considered a bug.

One example is the set of MySQL and forks of MySQL, where there are mysql51, mysql55, mysql56, mariadb, mariadb-10.0, mariadb-11.0, percona, possibly among others. port select lets you choose which of these becomes the version run, when you simply run mysql or other commands from the MySQL suite.

In your case, you have probably previously used sudo port select --set php php73. To make PHP 8.2 your default, run sudo port select --set php php82. Run port select --summary to see the currently selected option.