Last Updated: February 25, 2016
·
561
· raphaelstolt

Check for module existence and version

In case you need check the existence of a given PHP module/extension, the following one-liner comes in handy and no old-skool phpinfo() look-up is needed.

Check for existing module:

$ php -m | grep xdebug | wc -l
1

Check for non-existing module:

$ php -m | grep mongo | wc -l
0

In case you need some more detailed info (e.g. version number) about an existing module you can issue php --ri <module-name> and will get the desired info.

$ php --ri json
json

json support => enabled
json version => 1.2.1