移植LASP到嵌入式arm板(appweb7.2+php7.3.5)

本文详细记录了在ARM平台上移植LASP(包括appweb、php等组件)的过程,从配置环境到解决编译中遇到的各种问题,如依赖库的安装、编译选项的选择、配置文件的修改等。作者强调了configure脚本的重要性,以及在php编译时遇到的符号引用问题和多线程兼容性。最终,作者给出了成功运行的配置修改建议,包括appweb.conf、install.conf和php.ini的调整,以确保系统稳定运行。

编者按

          始于一次对朋友的帮忙,一时兴起,自觉移植LASP不是难事,不想竟耗时一个周末方才搞定。期间走了很多弯路,本着分享的初心,记录移植流程及疑难点。

        移植成果见资源:

https://download.csdn.net/download/qq_25145163/21724411

移植步骤

  1.1 说明

        本次移植涉及的源码包括以下:

   appweb7.3、php7.3.5、libiconv-1.16、libxml2-2.9.9 、openssl1.0.1t、sqlite-autoconf-3280000、zlib-1.2.11

        appweb编译需openssl、php库;

        php编译需libz、libxml2、sqlite3、openssl、libiconv(用于支持spa的web展示)

        编译前需先设置好交叉编译链工具,选用与根文件系统相同的交叉编译链是最好的了,否则可能出现依赖库不兼容的情况。本人编译根文件系统编译采用5.4版本,LASP编译采用7.4版本,运行时出现ld-2.25.so、libc-2.25.so等不兼容问题,最终替换l7.4版本sysroot下lib方可正常使用。

1.2 编译 zlib

        源码:http://www.zlib.net/

./configure  --prefix=/opt/work/SC/install/zlib/ --shared

手动对Makefile进行如下修改:

CC=gcc 改为:
CROSS_COMPILE=arm-linux-
CC=$( CROSS_COMPILE) gcc
LDSHARED= gcc 改为:LDSHARED=$( CC) 
CPP= gcc - E 改为:CPP=$( CC )  - E
AR= ar rc 改为:AR=$( CROSS_COMPILE ) ar rc

make

make  install

1.3 编译 sqlite

        源码:https://www.sqlite.org/download.html

./configure --prefix=/opt/work/SC/install/sqlite3/ --host= arm-linux   

make

make install

1.4 编译 libxml2

        源码:http://xmlsoft.org/downloads.html

./configure --prefix=/opt/work/SC/install/libxml2-2.9.9/  --host=arm-linux  --with-zlib=/opt/work/SC/install/zlib/  --without-python

make

make install

1.5 编译 libiconv

        源码:http://www.gnu.org/software/libiconv

./configure --prefix=/opt/work/SC/install/libiconv-1.16 --host=arm-linux

make

make install

1.6 编译 openssl 

        源码:https://www.openssl.org/source/ 

./Configure --prefix=/opt/work/SC/install/openssl os/compiler:arm-linux-gcc -fPIC

make

make install

1.7 编译 php  

        源码: https://www.php.net/downloads.php 

        配置项:目前主要支持openssl、libxml、libz、sqlite3、libiconv;
        支持的ext:iconv、dba、json、 pdo、pdo_sqlite、sqlite3、xmlreader、xml、xmlwriter。
后续若需扩展,则需自行扩展配置项+提供依赖库包

./configure --prefix=/opt/work/SC/install/php-7.3.5/ --host=arm-linux  --with-libxml-dir=/opt/work/SC/install/libxml2-2.9.9 --with-openssl-dir=/opt/work/SC/install/openssl --with-zlib-dir=/opt/work/SC//install/zlib/ --with-config-file-path=/opt/etc/ --with-config-file-scan-dir=/opt/etc/ --disable-all  --enable-embed --enable-session --enable-libxml=shared --enable-xml=shared --enable-xmlreader=shared --enable-xmlwriter=shared --enable-json=shared --enable-inifile=shared --enable-fpm --enable-phpdbg --enable-phpdbg-debug --enable-debug --enable-sigchild  --enable-pdo=shared  --with-sqlite3=shared,/opt/work/SC/install/sqlite3 --with-pdo-sqlite=shared,/opt/work/SC/install/sqlite3 --with-zlib --with-libzip --enable-maintainer-zts --enable-zend-signals --with-tsrm-pthreads --enable-calendar --enable-dba=shared --with-iconv=/opt/work/SC/install/libiconv-1.16 --with-openssl=/opt/work/SC/install/openssl LDFLAGS="-L/usr/local/arm/7.4.1/arm-linux-gnueabi/sysroot/lib/" LIBS="-ldl -lpthread"

make

make install

 1.8 编译 appweb  

        源码:https://www.embedthis.com/appweb/download.html

        上述链接仅展示最新版,若要下载旧版,可在页面内跳转到github中下载指定tag版本。

        修改配置需要使用metoo工具,需要另行编译metool,此处直接对Makefile进行修改。对arm来说,实际调用的makefile是projects/appweb-linux-default.mk,我们直接对其进行修改即可

SHOW=1 make

SHOW=1 make install 

 后记

  1.编译相关

       1.1 编译方面,主要是php的编译耗费了太多时间和精力,配置项繁多,--enable  --with --without  dir等等搞的人不胜其烦。configure执行时会根据配置的依赖库路径、头文件、库文件等信息去判断、处理系统层级诸多信息,稍有配置错误,就会导致后续编译出错。

        另外,configure文件中有3处执行时总是有问题,故对这些内容记性了修改

 修改如下:

 

        若实在configure不过,可拷贝下载资源中提供的修改后的configure文件。

        LDFLAGS="-L/usr/local/arm/7.4.1/arm-linux-gnueabi/sysroot/lib/"

        这一部分不是必须的,当时是使能了--enable-libgcc 后报找不到libgcc_s.so.1,才额外增加该配置。

enerating files
configure: creating ./config.status
creating main/internal_functions.c
creating main/internal_functions_cli.c
+--------------------------------------------------------------------+
| License:                                                           |
| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE.  By continuing this installation |
| process, you are bound by the terms of this license agreement.     |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
+--------------------------------------------------------------------+

Thank you for using PHP.

config.status: creating php7.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/fpm/php-fpm.conf
config.status: creating sapi/fpm/www.conf
config.status: creating sapi/fpm/init.d.php-fpm
config.status: creating sapi/fpm/php-fpm.service
config.status: creating sapi/fpm/php-fpm.8
config.status: creating sapi/fpm/status.html
config.status: creating sapi/phpdbg/phpdbg.1
config.status: creating sapi/cgi/php-cgi.1
config.status: creating main/php_config.h
config.status: executing default commands

        configure后最好浏览下config.log,对新添加的配置部分着重查看、确认,如果存在error/no等信息,则需要解决,否则即使编译通过也会埋坑。

        如下图所示,configure中存在大量的、全面的符号、函数、数据类型等内容的处理,有些严重的会直接报错、有些则会屏蔽某些功能,或添加某些定义(如typedef数据类型)

        编译后可通过查看Makefile、观察编译输出信息判断配置是否存在问题。

看依赖头文件 

-I /usr/include ...

出现这种情况,基本是configure没有找到依赖项的头文件,自动选择了默认路径,再编译iconv功能时没有指明libiconv路径,出现这个问题,导致头文件依赖出现问题,造成数据类型存在重复定义

 看依赖库文件

-lxxx -Lxxx  

例如:

编译pdo_sqlite、sqlite3没有链接-lsqlite3,则编译可以成功,运行时会报错找不到libsqlite3或相关符号

配置时没有指定LIBS="-ldl",则configure时会判定系统不支持动态加载库,从而编译的php不支持加载ext扩展库,仅支持builtin,即不支持--with-xx=shared

         1.2 appweb编译报__stack_chk_fail 未定义的引用

        本人在编译时未出现此类错误,但若出现此类错误,可在 projects/appweb-linux-default.mk中将-fstack-protector删掉即可。

 

2.php+appweb 

        在新版appweb中是支持多线程模式的,其使用phpHandle7.c来处理php相关部分,它也要求php必须是线程安全的(--enable-maintainer-zts),这与以往有很大不同。php必须编译为zts版本。 appweb默认支持并发5个任务。为兼容旧有php项目,需要特殊设置为仅允许一个任务/线程,否则,旧项目开发时没有考虑到多线程的问题(全局变量临界资源等),则很容易导致appweb崩溃。在这一部分,排查问题耗费了一天的时间,经历了频繁崩溃、移植gdb、定位崩溃位置、确定多线程问题、修改源码中最大任务数值的一系列煎熬过程,才使得appweb+php正常工作。最后浏览src/config.c意外的发现可以通过配置文件设置最大任务数。

3.配置修改

         appweb.conf:

1.开启trace信息
TraceLog "access.log" level=5 size=10MB backup=5 anew formatter=common format="%h %l %u %t "%r" %>s %b %n"

2.设置旧版php兼容
<if PHP_MODULE>                                                      
    LoadModule phpHandler libmod_php                  
    AddHandler phpHandler php                                          
    LimitWorkers 1                                                           
</if>   

        install.conf:

set LOG_DIR "/opt/var/log/appweb"
set CACHE_DIR "/opt/var/spool/appweb/cache"
Documents "/opt/var/www/appweb
DirectoryIndex index.php  index.html
LoadModulePath "/opt/lib"
Listen 80
<if SSL_MODULE>
ListenSecure 443 
</if>

        php.ini:

1.屏蔽NOTICE
error_reporting = E_ALL & ~E_NOTICE     
2.设置ext模块位置
extension_dir = "/opt/lib"  

4.成果

 ./appweb --config /opt/etc/appweb.conf &

默认会把调试、错误信息打印到日志文件,但这不方便调试,可借助参数打印到终端:

--log stdout:5      --trace stdout:5     等级范围都是0-5,可自行调节。

打印到终端后,则不会保存到日志文件中

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值