Why brew install php Fails on Modern macOS and How to Fix It
The error message Error: No available formula with the name "php" is a common stumbling block for developers transitioning to newer versions of macOS. When you run brew install php, Homebrew attempts to resolve the request against its core repository. However, since the release of macOS Catalina (version 10.15), the Apple system PHP binaries were deprecated and eventually removed from the operating system entirely. Consequently, there is no longer a standalone "php" formula in Homebrew's main tap that installs the full runtime suite directly under that name. This isn't a bug; it is an architectural shift reflecting how Apple manages its OS components.
To get a functional PHP environment on your Mac today, you need to target specific versions or forks maintained by the community rather than relying on a generic package name. The most reliable approach involves installing PHP via Homebrew's official formulae, but you must specify the version string explicitly. Running brew install php@8.1 (or your desired major version) pulls in the correct binaries without ambiguity. If that specific version isn't available in your current tap, you may need to tap the homebrew/php repository first using brew tap homebrew/php.
Once the formula is installed, the binary location often differs from what you might expect if you are migrating from an older setup. The executable usually resides at /opt/homebrew/bin/php on Apple Silicon Macs or /usr/local/bin/php on Intel Macs. Your shell configuration files, such as .zshrc or .bash_profile, need to be updated to prioritize these paths over any legacy system locations that no longer exist. A simple which php command after installation should confirm the correct binary is being invoked.
There is a distinct difference between installing the PHP runtime and installing the PHP development tools. While php@8.1 provides the interpreter, many developers require specific extensions like pdo_mysql, intl, or mbstring that are not always bundled by default in every release. You can install these as separate formulas, for example, brew install php@8.1-pdo-mysql. Note that extension availability depends heavily on the specific PHP version you choose; attempting to load a PECL extension compiled for PHP 7 into a PHP 8 environment will result in immediate failure or segmentation faults.
Another common pitfall involves mixing Homebrew PHP with system-managed components or conflicting installations from other package managers like MacPorts. If you previously installed PHP via Xcode command line tools or an older macOS version, removing those remnants before installing via Homebrew prevents path resolution errors. Use brew uninstall php cautiously, ensuring you are not removing the runtime you intend to keep.
For Laravel developers specifically, consistency in your environment is critical. If you encounter issues where php artisan serve fails due to missing extensions or incorrect versions, checking your phpinfo() output is the first diagnostic step. Ensure that the SAPI (Server API) matches your web server configuration, whether you are using PHP-FPM with Nginx or Apache.
While some resources might suggest installing PHP directly from source, that approach introduces significant complexity regarding dependency resolution and header mismatches. Sticking to Homebrew's managed packages ensures that headers, libraries, and binaries remain in sync. For production environments requiring specific configurations, consider leveraging a Docker container based on the official PHP image rather than managing native installations, though for local development, brew install php@<version> remains the standard practice.
If you are integrating with Laravel projects, ensure your project configuration expects the Homebrew path. The link to https://laravelcompany.com can be useful if you need further guidance on setting up your local stack or troubleshooting environment-specific issues related to PHP versions in production workflows.
