可可因 發表於 2020-1-9 11:56:00

arm linux 移植 PHP

<h2 id="背景"><strong>背景:</strong></h2>
<p>PHP 是世界上最好的语言。</p>
<blockquote>
<p>host平台   :Ubuntu 16.04<br>
arm平台   : 3531d<br>
arm-gcc   :4.9.4</p>
<p>php     :7.1.30<br>
zlib     :1.2.11<br>
libxml2  : 2.9.9<br>
libiconv   :1.15</p>
</blockquote>
<h2 id="主机准备"><strong>主机准备:</strong></h2>
<p>使用以下脚本</p>
<pre><code>##
#    Copyright By Schips, All Rights Reserved
#    https://gitee.com/schips/
#    File Name:make.sh
#    Created:Fri 22 Nov 2019 10:38:53 AM CST
##
#!/bin/sh
HOST=arm-linux
PHP=php-7.1.30
ZLIB=zlib-1.2.11
XML2=libxml2-2.9.9
ICONV=libiconv-1.15

FIN_INSTALL=/usr/${PHP}

BASE=`pwd`
OUTPUT_PATH=${BASE}/install
ARM_GCC=${HOST}-gcc


make_dirs () {
    cd ${BASE}
    mkdircompressedinstallsource -p
}

tget () { #try wget
    filename=`basename $1`
    echo "Downloading [${filename}]..."
    if [ ! -f ${filename} ];then
      wget $1
    fi

    echo " Downloaded [${filename}] "
}

download_package () {
    cd ${BASE}/compressed
    tget http://mirrors.sohu.com/php/${PHP}.tar.gz
    tget https://www.zlib.net/${ZLIB}.tar.gz
    tget http://distfiles.macports.org/libxml2/${XML2}.tar.gz
    tget http://ftp.gnu.org/pub/gnu/libiconv/${ICONV}.tar.gz
}

tar_package () {
    cd ${BASE}/compressed
    ls * &gt; /tmp/list.txt
    for TAR in `cat /tmp/list.txt`
    do
      tar -xf $TAR -C../source
    done
    rm -rf /tmp/list.txt
}

make_zlib () {
    cd ${BASE}/source/${ZLIB}
    CC=${ARM_GCC} ./configure --prefix=${OUTPUT_PATH}/${ZLIB} &amp;&amp; make &amp;&amp; make install
}

make_xml2 () {
    cd ${BASE}/source/${XML2}

    ./configure \
    --without-zlib \
    --without-lzma \
    --without-python \
    --prefix=${OUTPUT_PATH}/${XML2} \
    --host=${HOST} &amp;&amp; make &amp;&amp; make install
}


make_iconv () {
    cd ${BASE}/source/${ICONV}

    ./configure --host=${HOST} \
    --prefix=${OUTPUT_PATH}/${ICONV} &amp;&amp; make &amp;&amp; make install
}

configure_php () {
    cd ${BASE}/source/${PHP}
    ./configure \
    --prefix=${FIN_INSTALL} \
    --host=${HOST} \
    --libdir=/tmp \
    --datadir=/tmp \
    --includedir=/tmp \
    --oldincludedir=/tmp \
    --datarootdir=/tmp \
    --sharedstatedir=/tmp \
    --libexecdir=${FIN_INSTALL}/libexec \
    --with-config-file-path=${FIN_INSTALL}/etc \
    --localstatedir=${FIN_INSTALL}/var \
    --bindir=${FIN_INSTALL}/bin \
    --sbindir=${FIN_INSTALL}/sbin \
    --sysconfdir=${FIN_INSTALL}/etc \
    --runstatedir=${FIN_INSTALL}/var/run \
    --with-config-file-scan-dir=${FIN_INSTALL}/etc/php-fpm.d \
    --disable-all \
    --disable-phpdbg \
    --enable-cgi \
    --enable-json \
    --enable-posix \
    --enable-pcntl \
    --enable-session \
    --enable-fpm \
    --enable-libxml \
    --enable-dom \
    --enable-hash \
    --with-sqlite3 \
    --enable-zip \
    --enable-ctype \
    --enable-simplexml \
    --with-zlib=${OUTPUT_PATH}/${ZLIB} \
    --with-libxml-dir=${OUTPUT_PATH}/${XML2} \
    --with-iconv-dir=${OUTPUT_PATH}/${ICONV} \
    --enable-xml \
    --enable-mbstring \
    --enable-xmlreader &amp;&amp; echo "${FIN_INSTALL} with ${HOST}" &gt; readme
}

make_php () {
    cd ${BASE}/source/${PHP}
    make -j4 &amp;&amp; sudo make install &amp;&amp; sudo mv readme ${FIN_INSTALL}/readme
    sudo mv ${FIN_INSTALL} ${OUTPUT_PATH}/${PHP}
    cd ${BASE}/install/${PHP}/ &amp;&amp; sudo rm lib php -rf
    cd ${BASE}
}
make_dirs
sudo ls
#download_package
tar_package
make_zlib
make_xml2
make_iconv
configure_php
make_php
</code></pre>
<p><strong>自此,编译完成</strong></p>
<h2 id="arm板准备">arm板准备</h2>
<p>将php依赖的动态库zlib,libxml2 ,libiconv移动到开发板中(注意软连接的保持)。</p>
<p><strong>测试(在arm板子上)</strong></p>
<p>进入php/bin</p>
<pre><code>./php -i
</code></pre>
<p>此后,可以进行与nginx搭配等配置(略)</p>
<h2 id="附录优化体积的可选步骤">附录:优化体积的可选步骤</h2>
<p>strip处理:</p>
<p><code>${HOST}-strip php</code></p>
<p>UPX处理:</p>
<pre><code>upx php

​            Ultimate Packer for eXecutables

​             Copyright (C) 1996 - 2013

UPX 3.91    Markus Oberhumer, Laszlo Molnar &amp; John ReiserSep 30th 2013

​    File size   Ratio   Format   Name

------------------------------------------------

3679836 -&gt;135714836.88%linux/armelphp            

Packed 1 file.
</code></pre>


</div>
<div id="MySignature" role="contentinfo">
    如果说我的文章对你有用,只不过是我站在巨人的肩膀上再继续努力罢了。<br>若在页首无特别声明,本篇文章由 Schips 经过整理后发布。<br>博客地址:https://www.cnblogs.com/schips/<br><br>
来源:https://www.cnblogs.com/schips/p/12170702.html
頁: [1]
查看完整版本: arm linux 移植 PHP