Installing the Fileinfo PECL module on a Media Temple dedicated virtual (dv) server

This post describes how to install the PECL Fileinfo extension on a Media Temple dedicated virtual (dv) 3.5 server. A future post will describe what the Fileinfo extension does and why you might want to install it.

As of PHP 5.3.0, the Fileinfo extension is enabled by default and is no longer maintained at PECL. However, the Media Temple (dv) 3.5 service only includes PHP 5.2.6, so we’ll need to manually install it.

Please note that prior to installing Fileinfo, you’ll need to make sure that root access has been enabled on your (dv) and that the developer tools have been installed. Both of these actions can be completed from the Media Temple AccountCenter. For more information on enabling root access, please review the first two articles in the references/more info section below. The third link is to an article on the developer tools.

Once you’re sure that you have root access and that the developer tools are installed, SSH into your (dv). If Media Temple had the PECL binary installed, we could easily install Fileinfo by using the following statement from the command line: pecl install fileinfo.

Since we can’t, we’ll need to install Fileinfo from source. As the root user, enter the following statements into the terminal:

mkdir /var/pecl-install
cd /var/pecl-install
tar -zxf Fileinfo-1.0.4.tgz
cd Fileinfo-1.0.4
make install
cd /var
rm -f -r pecl-install

First, we download and unpack the extension in our working directory /var/pecl-install. Next we phpize the contents (i.e. prepare the build environment for a PHP extension). Once that’s done, we perform a standard configure and make routine to install the module. The final two commands remove our working directory from the server.

The outcome is that our extension,, should be created and exist in /usr/lib/php/modules. However, PHP still doesn’t know about it. To activate the extension we need to add a line to our php.ini file.

From the command line, enter vi /etc/php.ini. Scroll down until you hit the extensions section of the file and then press i to enter vi’s insert mode. Add and then press <esc> to exit insert mode and return to command mode. Type :wq<return> to exit vi and save your changes.

The final step to activate the Fileinfo extension is to restart the web server. From the command line enter:

/etc/init.d/httpd stop
/etc/init.d/httpd start

At this point, if you were to run phpinfo() on your server, you’d see that fileinfo is listed among the loaded modules, and if you tried to use any of the Fileinfo functions, you’d find they’d run without error.

However, if you actually try to use Fileinfo to determine the MIME type of a file, you’ll discover it still doesn’t work! The reason why is that Fileinfo depends on a "magic" file to determine the MIME type and, on a Media Temple (dv), it cannot access this file without our next (and final) step.

By default, Media Temple restricts PHP from accessing files outside of httpdocs using the open_basedir directive. However, to use Fileinfo, we have to let PHP access the directory that contains the "magic" file, in this case /usr/share/file/.

So, from the command line as root, enter (replacing with your actual domain!):

cd /var/www/vhosts/
vi vhost.conf

Enter vi's insert mode and add the following lines to the empty vhost.conf file:

<Directory "/var/www/vhosts/">
php_admin_value open_basedir "/var/www/vhosts/"

Exit vi (saving your changes!) and reconfigure the server to look for the new vhost.conf file by entering:

/usr/local/psa/admin/sbin/websrvmng --reconfigure-vhost

Restart the web server once again:

/etc/init.d/httpd stop
/etc/init.d/httpd start

And that's it! Fileinfo should be now be successfully installed and activated! For more info on changing the open_basedir configuration, please see the last link in the resources/more info section below.

References/More info

  1. Media Temple KB. (dv) An introduction to the root user
  2. Media Temple KB. Disabling SSH Login for root user
  3. Media Temple KB. (dv) 3.5 Tech Specs – Developer’s Tools package listing.
  4. Jelly and Custard. Installing PECL Modules
  5. Media Temple KB. How can I edit php.ini on the (dv) & (dpv) Dedicated-Virtual Servers?
  6. Media Temple KB. (dv) HOWTO: Enable PEAR/Set open_basedir and include_path.

12 thoughts on “Installing the Fileinfo PECL module on a Media Temple dedicated virtual (dv) server

  1. Pingback: » Blog Archive » Using the PHP Fileinfo extension

  2. Pingback: Tastee ( links! (July 29th)

  3. Pingback:   Zend Framework on MediaTemple DV by eingko weblog

  4. Pingback: Two for Web developers | theMechanism

  5. Pingback: PECL Fileinfo Error - cPanel Forums

  6. Pingback: How To Configure The Various W3TC Plugin Settings For Your WordPress Blog | GadgetUpdated

  7. Pingback: Frederick de Guzman » Blog Archive » How To Configure The Various W3TC Plugin Settings For Your WordPress Blog

  8. Pingback: Install Fileinfo module to PHP prior than 5.3 on CentOS

  9. Pingback: Ujwal Trivedi — rackspace cloud files php api errors

  10. Dude you’re awesome! I was trying to install the uploadprogress extension from pecl on a dv but could not get anywhere and could not find anything on the web about this. You da man!!

Leave a Reply