Homebrew-php已弃用,PHP72扩展安装及替代方案咨询
Hey there! I totally get the confusion since the old homebrew-php repo got merged into Homebrew core—let's break down how to get your PHP 7.2 setup with the extensions you need, no extra repo sources required.
First, Update Homebrew and Install PHP 7.2
Before diving in, make sure your Homebrew is up to date to avoid compatibility hiccups:
brew update && brew upgrade
Homebrew keeps older PHP versions as versioned formulae, so to install PHP 7.2 specifically:
brew install php@7.2
Once installed, link it to make it your active PHP version (critical if you have newer PHP builds already set up):
brew link php@7.2 --force --overwrite
Installing Your Required Extensions
Let's tackle each extension one by one:
1. intl
Good news—intl is compiled by default with Homebrew's php@7.2 package. Verify it's loaded by running:
php -m | grep intl
If it doesn't show up, try reinstalling PHP 7.2 (uninstall first with brew uninstall --force php@7.2 then re-run the install command).
2. opcache
Just like intl, opcache is included by default and usually enabled out of the box. Confirm it's active with:
php -m | grep opcache
If you need to tweak its configuration, find the PHP 7.2 ini file at /usr/local/etc/php/7.2/php.ini and ensure these lines are present and uncommented:
zend_extension="opcache.so" opcache.enable=1 opcache.enable_cli=1
3. MySQL-related Extensions
Note: The legacy mysql extension is deprecated in PHP (and removed in newer versions). Homebrew's php@7.2 includes the recommended replacements mysqli and PDO_MySQL by default. Verify they're loaded with:
# Check mysqli php -m | grep mysqli # Check PDO_MySQL php -m | grep pdo_mysql
If you absolutely need the outdated mysql extension (not recommended), you can install it via PECL (PHP's official extension manager):
pecl install mysql
After installation, follow the prompts to add the extension line to your php.ini file.
No Extra Repo Needed!
You don't need to add any third-party Homebrew repos anymore. Homebrew core maintains the PHP formulae, and any missing extensions can be installed via PECL, which works seamlessly with Homebrew-installed PHP.
内容的提问来源于stack exchange,提问作者ufk

