This article explains how I overcame the compiler crash, of fileinfo module, while compiling PHP 7.1.12 from source on an armv7l board.

I've been using an Olimex OlinuXino a10 Lime board for file server, DLNA server, torrent client, always-on-do-anything machine at home, and decided to use Nextcloud 12 for some files I may need to access when at work (or anywhere for the matter). Nextcloud needs at least PHP 5.6, my distribution, Linux oli 3.4.90+ #3 PREEMPT Tue Jun 10 09:17:04 EEST 2014 armv7l GNU/Linux, was using 5.4. No PHP 7 in the repositories, so I decided to compile it from source.

You probably know the process: download source file, unzip it, configure with options, make, make install.

The problem is that during make, cc compiler - gcc (Debian 4.6.3-14) 4.6.3 - crashed with the following message:

/bin/bash /home2/oli/build.from.source/php-7.1.12/libtool --silent --preserve-dup-deps --mode=compile cc -I/home2/oli/build.from.source/php-7.1.12/ext/fileinfo/libmagic 
-Iext/fileinfo/ -I/home2/oli/build.from.source/php-7.1.12/ext/fileinfo/ -DPHP_ATOM_INC -I/home2/oli/build.from.source/php-7.1.12/include -I/home2/oli/build.from.source/php-7.1.12/main 
-I/home2/oli/build.from.source/php-7.1.12 -I/home2/oli/build.from.source/php-7.1.12/ext/date/lib -I/usr/include/libxml2 -I/usr/include/freetype2 
-I/home2/oli/build.from.source/php-7.1.12/ext/mbstring/oniguruma -I/home2/oli/build.from.source/php-7.1.12/ext/mbstring/libmbfl 
-I/home2/oli/build.from.source/php-7.1.12/ext/mbstring/libmbfl/mbfl -I/home2/oli/build.from.source/php-7.1.12/ext/sqlite3/libsqlite -I/home2/oli/build.from.source/php-7.1.12/ext/zip/lib 
-I/home2/oli/build.from.source/php-7.1.12/TSRM -I/home2/oli/build.from.source/php-7.1.12/Zend    -I/usr/include -g -O2 -fvisibility=hidden -DZEND_SIGNALS   
-c /home2/oli/build.from.source/php-7.1.12/ext/fileinfo/libmagic/apprentice.c -o ext/fileinfo/libmagic/apprentice.lo 
cc: internal compiler error: Killed (program cc1)
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-4.6/README.Bugs> for instructions.
make: *** [ext/fileinfo/libmagic/apprentice.lo] Error 1

The PHP bug repo suggested for a similar problem that there was not enough memory for the compilation to proceed, and the kernel killed the cc process. It seems that the 512MB of the board were not sufficient. I thought that adding a 2GB swap file would solve the problem, but cc kept crashing.

After some googling i came across posts about cross-compiling source on on computer and using it on another. I thought I 'd give it a try. I won't go into details, but I used qemu-system-arm in order to run a armhf Debian image I found here. The readme provides instructions on how to boot the image ( I used the standard, without GUI, with 1GB memory ). The gcc was the same version as my board, which was a good sign. I repeated the process of configure and make and took the folder of the source code, looked for the files I needed in order for the make to skip compiling apprentice.lo . These are the following 2 files, in 3 different paths.

php-7.1.12/ext/fileinfo/libmagic/apprentice.o
php-7.1.12/ext/fileinfo/libmagic/apprentice.lo
php-7.1.12/ext/fileinfo/libmagic/.libs/apprentice.o

I copied them to their respective paths in the source folder of my board, restarted make, which picked up from where it stopped, skipping apprentice.lo, and completed successfuly. I have the files as attachments to the article, in case anyone tries to compile the same version of PHP on the same board.

Attachments:
Download this file (apprentice.tar.gz)apprentice.tar.gz[ ]259 kB