It seems the fileinfo extension cannot be installed for PHP 8.x in CentOS 7, now what?

Cannot install fileinfo extension for PHP 8.0, 8.1 in aapanel with CentOS 7

In the last days, experimenting with Magento 2 handled by a new web hosting panel I discovered recently, specifically aapanel, I found one of those bugs that would make a developer to scream for days. I installed 2 versions of PHP, the 7.4 and 8.1 and tried to install the dependencies of the magento project through composer with a simple composer install (using PHP 8.1 in the CLI). The installation threw the following exceptions:

Problem 1                                                                                                                                                                                                            
- league/mime-type-detection is locked to version 1.11.0 and an update of this package was not requested.                                                                                                         - league/mime-type-detection 1.11.0 requires ext-fileinfo * -> it is missing from your system. Install or enable PHP's fileinfo extension.

Problem 2

- league/mime-type-detection 1.11.0 requires ext-fileinfo * -> it is missing from your system. Install or enable PHP's fileinfo extension.
- league/flysystem-aws-s3-v3 2.4.3 requires league/mime-type-detection ^1.0.0 -> satisfiable by league/mime-type-detection[1.11.0].
- league/flysystem-aws-s3-v3 is locked to version 2.4.3 and an update of this package was not requested.

After noticing that the ext-fileinfo extension of PHP 8.1 wasn't installed, I proceeded to install it through the Software Store of aapanel (this aapanel really makes things easy to do) with a simple click:

aapanel fileextension php 8.1

However, the installation seemed to start but never ended, the process died and the extension never appeared as installed in PHP 8.1 (whatever you do, the extension never appears as installed and it will always be missing in PHP).

Just in the moment I was giving up already, I decided to change the CLI version of PHP from 8.1 to the 7.4. Then I tried to install the fileinfo extension, but this time, the extension was installed successfully:

fileinfo aapanel php 7.4

Curiously, the same happened to me during the installation of the same extension with Aapanel in Ubuntu 20.04 as well. So, it seems it isn't CentOS 7 related, but to something else.

Cause and solution

The fileinfo extension can be installed in the system as it can be compiled, however the compilation process is failing. The problem is related and seems to happen only to tiny servers with few resources, for example, this issue is happening on the nanode VPS in Linode (1GB Ram and 1 Core). The best solution would be to simply move to a bigger VPS that has at least 2 GB of physical RAM.

Alternatively, if switching the VPS is not an option, you may increase the available memory using SWAP. The first thing you need to do is to install the Linux Tools extension in the App Store:

Linux Tools Aapanel Plugin

After that, open the settings menu of this plugin and go to the Swap/virtual memory tab. In this tab, you need to add more virtual RAM to your server, in my case the physical memory is of 1GB, so I can create a Swap of 1GB:

Swap Size Linux Tools

Once the Swap has been created, you can proceed once again with the installation of the fileinfo extension through the PHP settings, it should work now as expected.

Happy coding ❤️!


Senior Software Engineer at Software Medico. Interested in programming since he was 14 years old, Carlos is a self-taught programmer and founder and author of most of the articles at Our Code World.

Sponsors