PHP has no class!

Recently I was working on a new project, but when I tried testing it on my DreamHost server, I got the ominous message…

“Fatal error: Class ‘finfo’ not found”

Oh noes! PHP defines several classes in its core, but many more are defined within modules/extensions. In my case, I was trying to use a class named finfo, which is part of the FileInfo module. It turns out that the default DreamHost PHP configuration file doesn’t load the FileInfo extension. Well, you’ve got two options when you run into this problem: you can rewrite your script, or you can just add that module.

“Is that hard?” you ask… Nope, it’s easy!

Easy like sunday morning

There are so many PHP modules out there that it’s not practical to add them all, but those crafty DreamHost developers planned for that. Starting with the PHP5.3 version, the DreamHost developers enabled a super simple way to modify the PHP configuration. Thanks to that, all you’ve got to do to enable a new PHP module is create a file named phprc in the proper directory. Anything you put in that phprc file will automatically be applied to the PHP configuration. Also, because the FileInfo module is already installed on the server, the fix was a simple one liner extension=”fileinfo.so”

That’s it, there’s no need to contact support or reboot the server or anything like that; just add a single line to the phprc file and wait a minute or two for any existing PHP processes to expire. The new settings will load automatically the next time a PHP process for your user starts up.

PHP is kind of a big deal.

Kind of a Big Deal

There are tons of scripts out there that use combinations of classes and modules. So, if you find your fancy new PHP based content management system spits out an error saying it can’t find a class, fear not! You may just need to take your PHP settings back to school.

For specifics on creating the phprc file, or hundreds of other topics, check out the DreamHost wiki:

http://wiki.dreamhost.com/Php.ini#phprc

If you have any questions, our support team is here for you 24 / 7.