Setup Multiple PHP Version on MacOS Using MacPorts

The MacPorts Project is an open-source community initiative to design an easy-to-use system for compiling, installing, and upgrading either command-line, X11 or Aqua based open-source software on the Mac operating system.

To that end we provide the command-line driven MacPorts software package under a 3-Clause BSD License, and through it easy access to thousands of ports that greatly simplify the task of compiling and installing open-source software on your Mac.

To Install MacPorts first download it from MacPort has a graphical installer, so it’s easy.


After Install completly, run this command to install php as your need :

sudo port install php81


If you want to Install some extention please follow below command

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


You can show php version you have in your system with following command

sudo port select --list php


And you should see

Available versions for php:
    php80 (active)


To switch PHP Version follow this command

sudo port select php php81


And check your version currently active with command

php --version
Zend Engine v4.1.5, Copyright (c) Zend Technologies
with Zend OPcache v8.1.5, Copyright (c), by Zend Technologies




Related Articles