Installing PHP on macOS provides a maintained interpreter for local development, Composer workflows, one-off scripts, and compatibility checks without relying on Apple-managed or app-bundled runtimes.

On recent macOS releases, the practical package-managed path is Homebrew. The php formula installs the active CLI binary plus helpers such as php-fpm and php-config under the same Homebrew prefix, so version checks, extension work, and later web-stack setup all start from one managed runtime.

A working Homebrew setup is required before starting because current macOS releases no longer bundle PHP. Apple Silicon systems normally install Homebrew under /opt/homebrew, Intel systems under /usr/local, older unsupported macOS releases may need another package source or source build, and an older PHP binary earlier in PATH can still mask the new install until the shell environment is refreshed.

Steps to install PHP with Homebrew on macOS:

  1. Check the Homebrew prefix so the later binary and configuration paths are easier to recognize.
    $ brew --prefix
    /opt/homebrew

    Apple Silicon Macs normally use /opt/homebrew. Intel Macs usually use /usr/local.

  2. Refresh Homebrew formula metadata before resolving the current PHP formula.
    $ brew update

    Homebrew often refreshes metadata automatically before brew install, but an explicit update surfaces tap or formula issues before the package transaction. If the refresh cannot reach the Homebrew API or taps, resolve that connectivity problem before continuing because the install step will fail for the same reason.

  3. Install the maintained PHP formula from Homebrew.
    $ brew install php

    If Homebrew reports that php is already installed and up-to-date, the runtime is already present and the next verification step can be used immediately. The unversioned php formula tracks the newest maintained branch, while versioned formulae such as php@8.4 and php@8.3 stay available separately for pinned project requirements.

  4. Confirm that Homebrew now records the PHP formula as installed in the current prefix.
    $ brew list --versions php
    php 8.5.4

    The output shows the formula name and the installed package version. If it is empty, the install did not complete in the current Homebrew prefix.

  5. Verify that the installed CLI interpreter answers from the Homebrew build.
    $ php -v
    PHP 8.5.4 (cli) (built: Mar 10 2026 23:15:23) (NTS)
    Copyright (c) The PHP Group
    Built by Homebrew
    Zend Engine v4.5.4, Copyright (c) Zend Technologies
        with Zend OPcache v8.5.4, Copyright (c), by Zend Technologies

    The first line confirms the active version and the cli SAPI. Build timestamps and extension lines vary by formula revision and architecture.

  6. List every php match in PATH so an older shim, symlink, or alternate install is visible before local projects start using the wrong runtime.
    $ type -a php
    php is /usr/local/bin/php
    php is /opt/homebrew/bin/php

    The first match is the command the shell runs. On some Apple Silicon Macs, an older /usr/local/bin/php symlink can still appear ahead of the canonical /opt/homebrew/bin/php path, so review and remove or reorder that older entry if it shadows the intended Homebrew runtime.

  7. Check the active CLI configuration path after the installation.
    $ php --ini
    Configuration File (php.ini) Path: "/opt/homebrew/etc/php/8.5"
    Loaded Configuration File:         "/opt/homebrew/etc/php/8.5/php.ini"
    Scan for additional .ini files in: "/opt/homebrew/etc/php/8.5/conf.d"
    Additional .ini files parsed:      (none)

    Homebrew installs php-fpm and the matching php-fpm.ini tree with the same formula, but a background service is only necessary when a local web server or socket-based workflow will use that FastCGI runtime. Start it later with brew services start php only when it is actually needed.