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

Brew下php71升级为php@7.1后SNMP扩展丢失,如何安装?

How to Install PHP SNMP Extension After Homebrew Moved PHP to Core Repository

Hey there, I totally get this frustration—when Homebrew moved PHP into their Core repository, those handy php71-snmp and php72-snmp formulae got axed, leaving us stuck without the SNMP extension. Don't worry, though—here are two solid ways to fix this:

This is the quickest and most straightforward approach for most users:

  • First, install the required SNMP system library. Run this in your terminal:
    brew install net-snmp
  • Double-check your PHP version to make sure you're targeting the right one (e.g., 7.1 or 7.2):
    php -v
  • Install the SNMP extension via PECL. If you have multiple PHP versions installed, use the version-specific PECL binary (like pecl7.1 or pecl7.2) instead of just pecl:
    pecl install snmp
  • Once installation finishes, enable the extension in your PHP config. Find your php.ini file location with php --ini, then add this line to the file:
    extension=snmp.so
  • Restart your web server (Apache, Nginx, etc.) and confirm the extension is loaded by running:
    php -m | grep snmp
    You should see "snmp" in the output if it worked.

Method 2: Compile the Extension Manually (If PECL Fails)

If PECL throws errors (sometimes happens with older PHP versions), compiling the extension yourself works reliably:

  • First, install dependencies (adjust the PHP version to match yours):
    brew install net-snmp php@7.1
  • Grab the PHP source code that matches your installed version. You can either download it from the official PHP site, or use the source that Homebrew cached for your PHP installation.
  • Extract the source archive, then navigate to the ext/snmp directory inside the source folder.
  • Run these commands to compile and install the extension:
    phpize
    ./configure --with-snmp=/usr/local/opt/net-snmp
    make
    make install
    
  • Just like in the PECL method, add extension=snmp.so to your php.ini file, restart your web server, and verify with php -m | grep snmp.

A quick note: If you switch between multiple PHP versions with Homebrew, make sure you enable the extension in the php.ini file for each version you use.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 07:25:03