sometimes compiling php requires more memory than your server has available. to be sure you have enough to compile php, use a server with more than 1 gb memory.
using ubuntu 20.04, compiling php7.4 with fileinfo was successful with 1 gb server memory but php8.0 fileinfo failed unless the server memory was increased to 2 gb.