PHP SNMP - Cannot find module

天涯浪子 提交于 2019-11-29 09:31:22

Apparently there are 2 environment variables you can set. One is MIBDIRS which is where all the MIB files are. Another is MIBS, which I believe is which SNMP modules you want to load. By setting MIBS to ALL, I was able to get rid of the errors.

I've got the same problem in Ubuntu with php7.1 and the solution was installing snmp package

apt-get install snmp

Open your php.ini and add some magical semicolon at line that look like:

extension=php_snmp.dll

It should look like:

;extension=php_snmp.dll

On linux, I was able to fix these by adding this to my /etc/php5/apache2/conf.d/snmp.ini file.

mibdir=/usr/share/snmp/mibs
mibs=all

The php package doesn't include mibs folder, what you have to do is download the source file of net-snmp and copy the folder into your php directory

download link https://sourceforge.net/projects/net-snmp/files/net-snmp/5.7.3/

after that, unzip the zip file and copy the mibs folder to your php directory

for exmaple,copy it to C:\PHP\Extras\mibs
Thne add a new system variable called MIBDIRS. Its value should be: C:\PHP\Extras\mibs

Finally, you can run php -m

and you issue will be resoved

I attach a screenshot for your reference.

I just fixed it on my machine here by adding

mibdirs +/var/lib/mibs/iana:/var/lib/mibs/ietf

to /etc/snmp/snmp.conf.

Faced a similar problem but in Ubuntu -

In /etc/snmp/snmp.conf -

# As the snmp packages come without MIB files due to license reasons, loading
# of MIBs is disabled by default. If you added the MIBs you can reenable
# loading them by commenting out the following line.
#mibs :

So , commenting out the mibs line in this file solved it .

Stumbled upon this migrating older Cacti to Ubuntu 16.

In Ubuntu/Debian package php-snmp depends on php7.0-snmp, neither of which come with MIBs or depend on snmp-mibs-downloader, hence SNMP module ends up being defunct with no MIBs available.

What you should do is install snmp-mibs-downloader (or equivalent) and let it download all available MIBs and see if that helps. If it doesn't, you might need to adjust mibdirs in /etc/php/x.x/mods-available/snmp.ini and/or manually load required MIBs (loading everything via mibs = ALL would work, but I consider it bad practice).

If no downloader is available, follow @Robin's advice and get MIBs from Net-SNMP

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!