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
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 (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, 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.