You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Mac无法卸载PHP 7.2求助:本地仍检测到该版本

Fixing PHP Uninstallation/Downgrade Issues on Mac for Magento

Hey there, let's work through this PHP problem—Macs love hiding PHP instances in unexpected places, which is why you're seeing that weird mismatch between php -v and Magento's detection. Here's a step-by-step breakdown to get this sorted:

Step 1: Locate All Hidden PHP Executables

First, we need to find every copy of PHP on your system, because Magento might be picking up one that's not in your terminal's PATH. Run these commands in your terminal:

  • Find all PHP files (ignoring permission errors):
    find / -name php -type f 2>/dev/null
    
    Look for paths like /usr/bin/php (system default), /usr/local/bin/php (Homebrew), or even custom install locations like /opt/homebrew/bin/php (for Apple Silicon Macs).
  • Check your current PATH to see which directories terminal uses to find PHP:
    echo $PATH
    

Step 2: Clean Up Homebrew PHP Residues

If you installed PHP via Homebrew, make sure you've fully removed the old version:

  • List any remaining PHP packages:
    brew list | grep php
    
  • Force-uninstall PHP 7.2 (and any related packages):
    brew uninstall --force php@7.2
    
  • Clean up Homebrew's cache and leftover files:
    brew cleanup
    

Step 3: Handle System-Supplied PHP

MacOS includes a default PHP version that's often tucked away in /usr/bin/php. Warning: Deleting system PHP can break some built-in tools, so try these safer options first:

  • Hide it from your terminal and Magento by modifying your shell config:
    Open ~/.zshrc (for Zsh) or ~/.bash_profile (for Bash) in a text editor, and add this line to prioritize other directories over the system PHP path:
    export PATH="/usr/local/bin:/opt/homebrew/bin:$PATH"
    
    Save the file and reload it with source ~/.zshrc or source ~/.bash_profile.
  • If you absolutely need to disable the system PHP (use with caution), rename it instead of deleting:
    sudo mv /usr/bin/php /usr/bin/php.old
    

Step 4: Fix Magento's PHP Detection

Magento doesn't always rely on your terminal's PATH—it might have scanned your system for PHP during initial setup. Here's how to fix that:

  • Check if Magento is using a hardcoded PHP path: Look in app/etc/env.php for a php_binary entry. If it exists, update it to your desired PHP version's path (e.g., /usr/local/opt/php@7.0/bin/php if you install 7.0).
  • When running Magento commands, explicitly call your target PHP version:
    /path/to/your/php7.0 bin/magento setup:install [your-install-flags]
    

Step 5: Install PHP 7.0 (If You Want to Downgrade)

If you'd rather downgrade to PHP 7.0 instead of fully removing PHP, use Homebrew:

  • Update Homebrew first:
    brew update
    
  • Install PHP 7.0:
    brew install php@7.0
    
  • Add it to your shell PATH (edit ~/.zshrc or ~/.bash_profile):
    export PATH="/usr/local/opt/php@7.0/bin:$PATH"
    export PATH="/usr/local/opt/php@7.0/sbin:$PATH"
    
  • Reload your shell config and verify the version:
    source ~/.zshrc
    php -v
    

Step 6: Verify the Fix

After following these steps, double-check:

  • Run which php in terminal—it should either point to your new PHP 7.0 or return "php not found" if you fully uninstalled.
  • Run the find command again to make sure no stray PHP executables are left:
    find / -name php -type f 2>/dev/null
    

Just a heads-up: Be careful with sudo commands—always double-check the paths you're modifying to avoid breaking your system.

内容的提问来源于stack exchange,提问作者Stefan Muntean

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 08:15:44