成果:

[email protected]:/tmp/home/root# php -v
PHP 7.0.15 (cli) (built: Jan 27 2017 18:00:16) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
[email protected]:/tmp/home/root# ll /opt/bin/php -h
-rwxr-xr-x    1 root     root        1.3M Jan 27 18:51 /opt/bin/php*

编译环境:Ubuntu 16.04 64Bit
机器配置:kimsufi KS4C i5-2400 , 16g ram , 2t hdd
路由器:Netgear R6250
首先下载需要的源代码

cd /home/R6250
wget http://be2.php.net/get/php-7.0.15.tar.gz/from/this/mirror -O php-7.0.15.tar.gz
wget http://xmlsoft.org/sources/libxml2-2.9.4.tar.gz
wget http://www.zlib.net/zlib-1.2.11.tar.gz
wget https://ftp.pcre.org/pub/pcre/pcre-8.40.zip
mkdir libxml2 pcre zlib php
tar zxvf libxml2-2.9.4.tar.gz 
tar zxvf zlib-1.2.11.tar.gz 
unzip pcre-8.40.zip 

编译libxml2

cd libxml2-2.9.4/
./configure --host=arm-brcm-linux-uclibcgnueabi --prefix=/home/R6250/libxml2 --with-python=/usr/include/python2.7
make
make install

编译zlib
zlib不支持--host选项,所以要指定CC。

cd ../zlib-1.2.11/
COLLECT_GCC=arm-brcm-linux-uclibcgnueabi-gcc
export CC=arm-brcm-linux-uclibcgnueabi-gcc
./configure --prefix=/home/R6250/zlib
make -j2
make install

编译pcre

cd ../pcre-8.40/
./configure --host=arm-brcm-linux-uclibcgnueabi --prefix=/home/R6250/pcre
make
make install

编译php

cd ../php-7.0.15/
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/projects/hnd/tools/linux/hndtools-arm-linux-2.6.36-uclibc-4.5.3/lib:/usr/local/lib:/usr/lib
CC=arm-brcm-linux-uclibcgnueabi-gcc \
CXX=arm-brcm-linux-uclibcgnueabi-g++ \
AR=arm-brcm-linux-uclibcgnueabi-ar \
RANLIB=arm-brcm-linux-uclibcgnueabi-ranlib \
LD=arm-brcm-linux-uclibcgnueabi-ld \
CFLAGS="-Os" \
CXXFLAGS="-Os"
./configure --host=arm-brcm-linux-uclibcgnueabi \
--prefix=/home/R6250/php \
--disable-all \
--enable-json \
--enable-posix \
--enable-pcntl \
--enable-session \
--disable-cgi \
--with-curl=/home/R6250/curl \
--with-zlib=/home/R6250/zlib \
--with-libxml-dir=/home/R6250/libxml2 \
--enable-libxml \
--enable-dom \
--enable-hash \
--with-sqlite3 \
--disable-phpdbg \
--enable-zip \
--enable-ctype \
--enable-simplexml \
--enable-xml \
--enable-mbstring \
--enable-xmlreader
make -j4
make install

编译完成,但是有点大。

[email protected]:/home/R6250/php/bin# ll -h
total 30M
drwxr-xr-x 2 root root 4.0K Jan 27 18:48 ./
drwxr-xr-x 7 root root 4.0K Jan 27 18:00 ../
-rwxr-xr-x 1 root root  14M Jan 27 18:43 php*
-rwxr-xr-x 1 root root  14M Jan 27 18:11 php-cgi*
-rwxr-xr-x 1 root root 2.2K Jan 27 18:11 php-config*
-rwxr-xr-x 1 root root  15M Jan 27 18:11 phpdbg*
-rwxr-xr-x 1 root root 4.5K Jan 27 18:11 phpize*

strip一下

[email protected]:/home/R6250/php/bin# arm-uclibc-linux-2.6.36-strip php
[email protected]:/home/R6250/php/bin# ll -h | grep php
-rwxr-xr-x 1 root root 3.6M Jan 27 19:10 php*

再UPX一下

[email protected]:/home/R6250/php/bin# upx php
                       Ultimate Packer for eXecutables
                          Copyright (C) 1996 - 2013
UPX 3.91        Markus Oberhumer, Laszlo Molnar & John Reiser   Sep 30th 2013

        File size         Ratio      Format      Name
   --------------------   ------   -----------   -----------
   3679836 ->   1357148   36.88%   linux/armel   php                           

Packed 1 file.
[email protected]:/home/R6250/php/bin# ll -h | grep php
-rwxr-xr-x 1 root root 1.3M Jan 27 19:10 php*

大小减小至1.3mb。
SCP到路由器上测试一下:

[email protected]:/tmp/home/root# ./php -v
PHP 7.0.15 (cli) (built: Jan 27 2017 19:16:38) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies

works fine.
参考资料:

  1. http://www.geekfan.net/7441/
  2. http://blog.csdn.net/npy_lp/article/details/6991704
  3. http://blog.csdn.net/stpeace/article/details/47090255
  4. http://blog.csdn.net/q1302182594/article/details/44975527
  5. https://my.oschina.net/eechen/blog/679342
  6. https://weicn.org/read/build_ssr_for_arm.html

标签: php, r6250

仅有一条评论

  1. wwng新年快乐

添加新评论