PHP on Your Mac — Without Installing PHP#
How do you run PHP on your Mac? Still brew install php, and hoping the
next brew upgrade doesn’t break your extensions?
I did that for years. It works, until one day it doesn’t. An extension won’t build. An upgrade quietly moves you to a PHP version your project isn’t ready for. And somewhere along the way, your Mac fills up with config files, libraries and leftover extensions in folders you never open.
I like to keep my computer clean#
I like knowing what’s on my machine. When I stop using a tool, I want to remove it and have it really gone, not leave pieces of it scattered around the disk for years.
A PHP installation never felt like that. It’s PHP itself, a pile of libraries it depends on, config files, extensions, and the memory of which ones you installed by hand last spring. Nobody knows what’s in there anymore, and nobody wants to touch it.
Docker for your server, but not for your command line?#
Think about how you run your projects today. The app runs in a container in production. The database, Redis and the queue probably run in containers on your laptop too.
Then you open a terminal, type php, and get a separate installation
that matches none of them: a different version, different extensions,
different settings. And it’s the PHP you use most: for Composer, for
tests, for every quick script.
Why does the one tool you use all day get the least care?
How quickly can you switch versions?#
One client is still on PHP 8.3. Your own project is on 8.5. A library you maintain has to work on both.
With a local install, switching means relinking, reinstalling extensions and hoping nothing else breaks. It should take seconds, not an afternoon.
So I stopped installing PHP#
I moved my PHP command line into Docker, the same way my servers already run. That gave me:
A clean Mac. The only thing installed is Docker. PHP, Composer and the extensions live in one image.
The commands I already know.
php,composer,php artisan: I type them exactly as before, in any project folder.Every extension I need, already there. No more building extensions by hand.
Versions in seconds. Each PHP version is just another image, and they sit side by side.
A real uninstall. Delete one image, and it’s gone.
I put the setup in a small open-source repository, so you can have it running in a few minutes:
👉 github.com/aln-1/docker-php-cli
Everything technical is in the README: what’s in the image, how to install it, how to add extensions or change the PHP version.
Your turn#
I’m curious how other people do this. How do you run PHP on your Mac: Homebrew, Docker, something else? And how do you switch between versions? Tell me in the comments.