Install PHP 8.1 CLI on MacOS using MacPorts

Simon
1 min readJul 16, 2019

--

MacPorts is a package manager for MacOS. It’s similar to HomeBrew. I prefer MacPorts that I found much more stable.

First download and install MacPorts. MacPort has a graphical installer, so it’s super easy.

Then you can install php81 simply by using the port command:

$ sudo port install php81

Let’s install some common extensions.

$ sudo port install php81-cgi php81-gd php81-curl php81-intl php81-iconv php81-gettext php81-mbstring php81-imap php81-mcrypt php81-xmlrpc php81-mysql php81-openssl php81-sockets php81-zip php81-tidy php81-opcache php81-xsl php81-sqlite

If you liste the different version you have. You should now see php81.

$ sudo port select --list php
Available versions for php:
none
php74
php80 (active)
php81

Select php81 has the active PHP version. With this command you can have multiple php version and quickly switch from one to the other.

$ sudo port select php php81

Check which PHP binary is used (should return /opt/local/bin/php). Perhaps you may need to restart you terminal.

$ which php

Check the version (should return “PHP 8.1.XX (cli)…”)

$ php --versionZend Engine v4.1.5, Copyright (c) Zend Technologieswith Zend OPcache v8.1.5, Copyright (c), by Zend Technologies

Done!

--

--

Responses (4)