Checking to See if Packages are Installed in PHP or Perl

I have this love/hate thing with open source technology. It’s great that it’s free, bugs are openly discussed instead of hidden away, and ultimately I think the open source technologies are more robust.

But here’s what always gets me: the packages and their dependencies.

Perl

At the bash prompt, you can type:
perl -e 'use Some::Package'

If the package is installed, nothing will happen. The one line script executes without complaint. But if you DON’T have that package installed, you’ll get an error like this:
Can't locate Some/Package.pm in @INC (@INC contains: /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi
[...]
/usr/lib/perl5/5.8.8/i386-linux-thread-multi /usr/lib/perl5/5.8.8 .) at -e line 1.
BEGIN failed--compilation aborted at -e line 1.

If that’s the case, you need to find and install that package. With Perl, the way to go is to get familiar with www.cpan.org — yes, it’s a fugly site, but you can search for packages and read up on them. If you want to download them, I recommend using the CPAN command line tool. You run this utility by simply typing cpan on the bash command line. Take the time to understand this utility! It will save you SO MUCH TIME.

PHP

PHP is nowhere near as verbose as Perl when it comes to error messages and debugging; it’s also a bit more mysterious when it comes to its package structure. You can get a lot of information by examining the output of the phpinfo() function. Simply write following script and hit it with a web browser:


<?php phpinfo(); ?>

On the command line, you can use rpm to see if a specific package is installed… however, good luck guessing what the package name is. For example, here you can check the version of the GD graphics library:
rpm -q php-gd
If the package is installed, the result should be something like:
php-gd-5.1.6-20.el5_2.1

You can also have a look in the php module directory. For Linux systems, it’s often here: /usr/lib/php/modules/

Search the File System

If you’re still frustrated, you can search the file system for the file — modules are FILES… they live SOMEWHERE. In Linux, you can use the find command:
find /path/to/start/search -name 'name_of_file'
E.g. to search for myfile.txt in the current directory or beneath, you’d type this:

find . -name myfile.txt

All the Linux file name metacharacters are valid, e.g. “*.txt” to search for all text files. The path can also be specified as any valid pathname, e.g. “~/” to refer to the current user’s home directory.

It’s a bit messy in there, but hopefully this helps you evaluate a system to see if your scripts or pages will actually work!