If you need to do local development of PHP projects on Mac, you’ll need PHP, probably multiple versions, even.

So, the first thing you’ll want to do, is installing MacPorts from the official website.

Once you did that, you fire up a Terminal and run:

sudo port selfupdate
sudo port install php74 php74-mysql php74-gd php74-curl php74-intl php74-iconv php74-mbstring php74-openssl php74-zip php74-exif php74-imagick
sudo port install php80 php80-mysql php80-gd php80-curl php80-intl php80-iconv php80-mbstring php80-openssl php80-zip php80-exif php80-imagick
sudo port install php81 php81-mysql php81-gd php81-curl php81-intl php81-iconv php81-mbstring php81-openssl php81-zip php81-exif php81-imagick
sudo port install php82 php82-mysql php82-gd php82-curl php82-intl php82-iconv php82-mbstring php82-openssl php82-zip php82-exif php82-imagick

This will install PHP 7.4 – 8.2 with multiple common extensions, which should give you an OK base to work with, especially if you need to develop for WordPress.

More database drivers

If you also need SQLite, run:

sudo port install php74-sqlite php80-sqlite php81-sqlite php82-sqlite

If you also need PostgreSQL (which will also install PostgreSQL):

sudo port install php74-postgresql php80-postgresql php81-postgresql php82-postgresql

If you also need Oracle DB (this does not currently work on arm64 (Apple Silicon), and instead only x86_64 and i386 (Intel Macs)!):

sudo port install php74-oracle php80-oracle php81-oracle php82-oracle

If you also need MongoDB:

sudo port install php74-mongodb php80-mongodb php81-mongodb php82-mongodb


If you also need Memcached:

sudo port install php74-memcached php80-memcached php81-memcached php82-memcached
sudo port load memcached

If you also need OPcache:

sudo port install php74-opcache php80-opcache php81-opcache php82-opcache


If you want to work with arbitrary-length integers using the GNU multiprocessing library:

sudo port install php74-gmp php80-gmp php81-gmp php82-gmp


If you want to do cryptographic operations with a known to be safe library (libsodium):

sudo port install php74-sodium php80-sodium php81-sodium php82-sodium


If you want to map IP addresses to geographic places (Make sure to obtain a MaxMind API key):

sudo port install php74-maxminddb php80-maxminddb php81-maxminddb php82-maxminddb
sudo port install php74-geoip php80-geoip php81-geoip php82-geoip
sudo port install geoipupdate
sudo mkdir -p /opt/local/share/GeoIP
sudo nano /opt/local/etc/GeoIP.conf
sudo geoipupdate

Updating all installed PHP versions

sudo port selfupdate
sudo port upgrade outdated
sudo port reclaim -N

Respond to all questions with yes.

Starting a local development server

To start a local development server, navigate to the “public” or “htdocs” (or whatever it’s called) directory of your project and run one of these:

php74 -S localhost:8080
php80 -S localhost:8080
php81 -S localhost:8080
php82 -S localhost:8080

Choose the command depending on the PHP version, then navigate to http://localhost:8080 in your web browser.


Once you know how, it’s straightforward to set up PHP. However, writing this article (and testing it), was not! I run this blog in my free time, consider donating a cup of coffee if I helped you out.