Tuesday, June 12, 2012

Cross Compile PHP for Arm

I just want to share some techniques to cross compile PHP for Arm using CodeSourcery Toolchain. Most of the resources I found out there do not show me how to include mysql client library as well as SimpleXML parser. These two libraries are needed for my case. Following are the how to Download PHP Source Code

I am using PHP 5.4.2. You can download it from php site.

Download libxml

I am using libxml2-2.8. TOOLCHAIN_DIR is the directory pointing to your toolchain library, in my case, it's /opt/toolchain/arm-2009q3/arm-none-linux-gnueabi/libc.

./configure --host=arm-linux-gnu --target=arm-linux CC=arm-none-linux-gnueabi-gcc
AR=arm-none-linux-gnueabi-ar LD=arm-none-linux-gnueabi-ld RANLIB=arm-none-linux-gnueabi-ranlib --prefix=[TOOLCHAIN_DIR]

Then issue

make install

Configure mysql config file

When compiling with MySQL support, I kept encountered following error:

mysqlnd/mysqlnd_portability.h:40:36: error: ./php_mysqlnd_config.h: No such file or directory

I got help from this site. Following is what you need to do to fix the missing file problem:
  1. Goto your php source folder, and navigate to ext/mysqlnd
  2. Then issue 
mv config9.m4 config.m4
sed -ie "s{ext/mysqlnd/php_mysqlnd_config.h{config.h{" mysqlnd_portability.h

Build PHP

Please note that I need to specify explicit location to libxml directory in order to compile successfully, please change the path to the location of your libxml library.

export CC=arm-none-linux-gnueabi-gcc
./configure --host=arm-linux --without-pear  --enable-libxml --with-libxml-dir=/opt/toolchain/arm-2009q3/arm-none-linux-gnueabi/libc --enable-simplexml --enable-mbregex --enable-sockets  --enable-soap --enable-pdo --with-pdo-sqlite --with-sqlite3 --with-openssl --enable-calendar --enable-mysqlnd --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --disable-all
make -j 12

Afterward, you can find the binary, php-cgi, inside sapi/cgi folder. Hope this tip could be useful.