从头编译PHP

in 日常 with 0 comment

前提配置

为了满足 pkg-config 的需求,首先导入环境变量

export PKG_CONFIG_PATH=/usr/local/armv7l-linux-musleabi/lib/pkgconfig/:/usr/local/armv7l-linux-musleabi/lib64/pkgconfig/

编译pcre2

GITHUB: https://github.com/PCRE2Project/pcre2/releases

./configure --enable-jit --enable-newline-is-anycrlf --host=armv7l-linux-musleabi --target=armv7l-linux-musleabi --prefix=/usr/local/armv7l-linux-musleabi/ LDFLAGS="-static" CCFLAGS="-fpic"
make && make install

注意如果从 git branch pull下来的,不要忘记初始化submodule,否则会报错

编译openssl

光猫自带openssl 1.1.x,所以建议使用旧版本可以省去很多空间
https://www.openssl.org/source/old/1.1.1/index.html

./config -fpic no-shared no-asm no-zlib no-sse2 no-comp no-dso --prefix=/usr/local/armv7l-linux-musleabi/ --cross-compile-prefix=armv7l-linux-musleabi- linux-armv4
make LDFLAGS="-latomic" CNF_CFLAGS="-pthread" CNF_CXXFLAGS="-std=c++11 -pthread" && make install

这里注意linux-armv4,否则编译会报错

编译zlib

GITHUB: https://github.com/madler/zlib/releases

export CC=armv7m-linux-musleabi-gcc
export AR=armv7m-linux-musleabi-ar
./configure --prefix=/usr/local/armv7l-linux-musleabi/ --static
make && make install

由于导入了环境变量,可能会导致编译其他的程序报错,重新打开终端即可

编译libxml2

GITLAB: https://gitlab.gnome.org/GNOME/libxml2/-/releases

LIBXSLT也是一样的方法,编译一个吧:https://gitlab.gnome.org/GNOME/libxml2/-/releases

./autogen.sh --host=armv7l-linux-musleabi --target=armv7L-linux-musleabi --prefix=/usr/local/armv7l-linux-musleabi/ CCFLAGS="-fpic" --enable-static --without-python
make && make install

编译PHP

 ./configure \
    --with-fpm-group=daemon \
    --with-layout=GNU \
    --with-config-file-path=/usr/data/.php.ini \
    --with-config-file-scan-dir=/usr/data/php \
    --with-zlib \
    --with-openssl \
    --without-cdb \
    --disable-flatfile \
    --disable-phar \
    --disable-dom \
    --disable-fileinfo \
    --disable-filter \
    --without-iconv \
    --without-libxml \
    --disable-simplexml \
    --disable-xml \
    --disable-xmlreader \
    --disable-xmlwriter \
    --disable-mbregex \
    --disable-opcache \
    --disable-tokenizer \
    --enable-fpm \
    --without-sqlite3 \
    --disable-pdo \
    PHP_EXTRA_VERSION=" for ArmEL Rounger" \
    --host=armv7m-linux-musleabi \
    LDFLAGS="-latomic -s -w" CCFLAGS="-fpic"

喝杯咖啡慢慢等吧,此编译版本

附上我编译的版本

Responses