Installing the Fileinfo PECL module on a Media Temple dedicated virtual (dv) server
21 February 2009 | Posted by Jeffrey Barke | 5 comments
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 has been 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 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. From the command line as root, enter the following statements:
mkdir /var/pecl-install
cd /var/pecl-install
wget http://pecl.php.net/get/Fileinfo-1.0.4.tgz
tar -zxf Fileinfo-1.0.4.tgz
cd Fileinfo-1.0.4
phpize
./configure
make
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 (ie 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, fileinfo.so, 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 extension=fileinfo.so 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 your-domain.com with your actual domain!):
cd /var/www/vhosts/your-domain.com/conf/
vi vhost.conf
Enter vi's insert mode and add the following lines to the empty vhost.conf file:
<Directory "/var/www/vhosts/your-domain.com/httpdocs">
php_admin_value open_basedir "/var/www/vhosts/your-domain.com/httpdocs:/usr/share/file:/tmp"
</Directory>
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 --vhost-name=your-domain.com
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
- Media Temple KB. (dv) An introduction to the root user
- Media Temple KB. Disabling SSH Login for root user
- Media Temple KB. (dv) 3.5 Tech Specs – Developer’s Tools package listing.
- Jelly and Custard. Installing PECL Modules
- Media Temple KB. How can I edit php.ini on the (dv) & (dpv) Dedicated-Virtual Servers?
- Media Temple KB. (dv) HOWTO: Enable PEAR/Set open_basedir and include_path.


February 25th, 2009 at 3:51 pm
Jeffrey, thanks for the timely how-to. I really found this helpful.
February 25th, 2009 at 11:49 pm
[...] my last post, I described how to install the Fileinfo PECL module on a Media Temple (dv) server, but I didn't really talk about what it does, why one might want to install it and how to use [...]
July 30th, 2009 at 12:02 am
[...] JeffreyBarke.net » Blog Archive » Installing the Fileinfo PECL module on a Media Temple … – A quick and dirty guide to installing Fileinfo on a MediaTemple server. I really appreciate guides like this when I'm trudging through server admin work. Share and Enjoy: [...]
November 1st, 2009 at 1:21 am
[...] If you’re going to using Flash, make sure to make the change in the .htaccess I mention here. Also, if you plan on uploading images at some point and would like MIME type validation and/or file information you’ll need to install the PECL fileinfo extension as explained by Jeffrey Barke on his website. [...]
November 11th, 2009 at 11:25 am
[...] first post I wrote describes how to compile and install Fileinfo on a Media Temple dedicated virtual server. The second talks about how to use Fileinfo and includes a wrapper class that might be [...]