Installing the fileinfo extension for PHP

You may have noticed that EWWW IO is capable of using several different mime-type libraries, but what are they, and why do you need them?

What's a "mime" type?

Simply put, the "mime" type can also be called the file type. It tells a computer what software to use when reading the file. For example, JPG, PNG, GIF, PDF, HTML, DOCX, and ZIP are some different mime types you might run into on the Internet. Some computers simply use the file extension to detect the mime type, but that isn't always reliable. For example, Mac OS X will often strip the file extensions when you save a file, because it doesn't need them.

Why do I need a mime-type library?

The nice thing about most files is that you don't need an extension to know what type a file is. The information about the type of file is usually embedded right at the beginning of a file itself. This is the information that the various mime-type libraries look for, instead of relying on the file extension.

Which one do I need?

There is a function named get_image_size that is generally available on every build of PHP that you will use with WordPress. It works well for images, but guess what? It doesn't work for anything that isn't an image. It also isn't as efficient as the fileinfo extension. If you don't want to optimize any PDF files, get_image_size will work just fine though.

However, if you DO want to optimize your PDF files, then EWWW IO needs a way of making sure that it is receiving PDF files back from the API. Without the fileinfo extension, it cannot do that. You may need to ask your webhost how to enable the fileinfo extension, as the configurations for webhosts are quite varied, but I'll show you an example for webhosts that use cPanel.

If you manage your own server, you can usually install fileinfo by looking for a package named php5-fileinfo php7.0-fileinfo, or php-fileinfo with apt or yum. For everyone else that uses cpanel, keep going...

Activating fileinfo

The first thing you want to look for the is the Software section of your cpanel (control panel). It will look something like this, but unless you use A2Hosting, it will be somewhat different.

On the far right, you'll see Select PHP Version, and that's what you want to look for. If your webhost doesn't have such an option, look for anything that says PHP, and see if you find a list similar to this:

That's a huge list, but remember the one we are looking for is named "fileinfo". Check the box next to fileinfo, and then hit save.

It may take a few minutes (or even up to an hour), but normally the changes are pretty quick. Confirm that you see the fileinfo extension active on the EWWW IO settings, then you can enable PDF compression, and go on your happy way. Happy Optimizing!

Still need help? Contact Us Contact Us