17

I've enabled the SNMP module was trying to the functions in the module. I have set the MIBDIRS environment variable to where I have my mibs but I'm still getting these "Cannot find module" warnings:

Cannot find module (IP-MIB): At line 0 in (none)
Cannot find module (IF-MIB): At line 0 in (none)
Cannot find module (TCP-MIB): At line 0 in (none)
Cannot find module (UDP-MIB): At line 0 in (none)
Cannot find module (HOST-RESOURCES-MIB): At line 0 in (none)
Cannot find module (SNMPv2-MIB): At line 0 in (none)
Cannot find module (SNMPv2-SMI): At line 0 in (none)
Cannot find module (NOTIFICATION-LOG-MIB): At line 0 in (none)
Cannot find module (UCD-SNMP-MIB): At line 0 in (none)
Cannot find module (UCD-DEMO-MIB): At line 0 in (none)
Cannot find module (SNMP-TARGET-MIB): At line 0 in (none)
Cannot find module (NET-SNMP-AGENT-MIB): At line 0 in (none)
Cannot find module (DISMAN-EVENT-MIB): At line 0 in (none)
Cannot find module (SNMP-VIEW-BASED-ACM-MIB): At line 0 in (none)
Cannot find module (SNMP-COMMUNITY-MIB): At line 0 in (none)
Cannot find module (UCD-DLMOD-MIB): At line 0 in (none)
Cannot find module (SNMP-FRAMEWORK-MIB): At line 0 in (none)
Cannot find module (SNMP-MPD-MIB): At line 0 in (none)
Cannot find module (SNMP-USER-BASED-SM-MIB): At line 0 in (none)
Cannot find module (SNMP-NOTIFICATION-MIB): At line 0 in (none)
Cannot find module (SNMPv2-TM): At line 0 in (none)

I know I have fixed this once but I can't seem to fix it again...what else can I try?

I'm on Windows.

PLui
  • 765
  • 1
  • 10
  • 27

9 Answers9

12

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.

PLui
  • 765
  • 1
  • 10
  • 27
  • These is similar to the bash environment and net-snmp tools (not sure if they are related to this). Glad you found an answer. :) – Colby Blair May 13 '13 at 14:40
  • I believe PHP is using Net-SNMP in the back so I suppose it makes sense why it's similar to the net-snmp tools you are familiar with :) – PLui May 13 '13 at 17:19
10

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

apt-get install snmp
marcus
  • 651
  • 6
  • 12
8

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
  • 2
    That's true if I don't need SNMP but in this case, I actually do. I think I might have found a way to work around it. Let me answer my own question. Thanks! – PLui May 10 '13 at 17:02
  • Did you see how to install SNMP? Look here http://technet.microsoft.com/en-us/library/cc759570(v=ws.10).aspx – Wesley Schleumer de Góes May 10 '13 at 17:24
  • Isn't the SNMP service to allow you to do snmpget/snmpwalk on the Windows machine? i.e. to monitor the Windows machine? If so, that's not what I want to do. I want to do gets & walks FROM a Windows machine, not TO. – PLui May 10 '13 at 19:08
  • For me it was the other way around, if I removed the semicolon my ampps localhost magicly works again. Thanks. – NLxDoDge Aug 25 '17 at 12:06
7

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.enter image description here

buqing
  • 925
  • 8
  • 25
  • I got the same problems in windows 10. It shows like this. 'MIB search path: c:/usr/share/snmp/mibs'. So, I copied the 'Mibs' files into that location. But there are no such location. I have to create share/snmp inside 'c:usr' folder. – white dark Aug 02 '21 at 11:03
6

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

tc0nn
  • 61
  • 1
  • 3
2

I just fixed it on my machine here by adding

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

to /etc/snmp/snmp.conf.

Teddy
  • 6,013
  • 3
  • 26
  • 38
2

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 .

2

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

Gendalph
  • 21
  • 3
1

I changed extension=snmp to ; extension=snmp in php.ini

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 02 '22 at 08:50
  • This worked perfectly for me. For people using XAMPP on Windows 10, click "Config" next to Apache service in the XAMPP control panel window to edit the "php.ini" file. Make the suggested changes, then restart the Apache service. – MLK.DEV Mar 03 '23 at 07:24