zoukankan      html  css  js  c++  java
  • S3C6410移植apache和php

    需要准备的东西:

    Apache-1.3.39 for linux

    Php-4.4.8 for linux

    Ubuntu amd64位 PC

    6410开发板,我用的是友善之臂

     

    交叉编译:

    交叉编译呢,简单地说,就是在一个平台上生成另一个平台上的可执行代码,即使用pc上的arm linuxgcc编译器编译好代码,并安装,然后把整个安装包放到开发板的相应目录。

     

    理论上只需在PC上编译安装arm版的apachephp即可,实际上由于在编译安装过程中需要用到某些文件,而这些文件在x86amd64平台上无法运行的,所以在编译arm版的apachephp之前,需要先使用gcc编译x86版的apachephp。

     

    Apachephp安装包放在/usr/local上,并且arm版的安装在apache_arm文件夹,x86版的安装在apache_test文件夹

     

    编译安装apache

    本地x86编译:

    tar xvf apache_1.3.39.tar.gz 

     

    cd /usr/local/apache_1.3.39/

     

    ./configure --prefix=/usr/local/apache_test/apache --enable-module=so

    出现:

    Syntax error — The configuration file is used only to
    define the list of included modules or to set Makefile in src
    options or Configure rules, and I don’t see that at all:
    `$(SRCDIR)/apaci`
    default
    default
    no
    no
    no
    yes
    no
    default
    no
    default
    default

    这是由于某些shell脚本文件使用了错误的interpreter,使用下面的命令就可以解决。

    # rm -f /bin/sh
    # ln -s /bin/bash /bin/sh

     

    再次./configure,没问题

     

    接着make

    出错:

    htpasswd.c:101:12: error: conflicting types for getline

     static int getline(char *s, int n, FILE *f)

                ^

    In file included from ../include/ap_config.h:1054:0,

                     from htpasswd.c:40:

    /usr/include/stdio.h:678:20: note: previous declaration of getline’ was here

     extern _IO_ssize_t getline (char **__restrict __lineptr,

                        ^

    make[2]: *** [htpasswd.o] Error 1

    make[2]: Leaving directory `/usr/local/apache_1.3.39/src/support'

    make[1]: *** [build-support] Error 1

    make[1]: Leaving directory `/usr/local/apache_1.3.39'

    make: *** [build] Error 2

     

    解决方法:

    这个问题是apache里自带了一个getline函数,并和stdio.h里的getline函数冲突了

    gedit gedit /usr/include/stdio.h

    找到getlline函数,把名字替换成parseline,保存,再makeok,编译成功,然后记得把parseline函数改回getline

     

    Make install也没有问题

    注:(这里必须要注意:事实上,我花了将近一个星期的时间去移植,第一次移植时我是老老实实去make install了,结果在最后,我在pc上运行arm版的apache时竟然不报错,这是有问题的,因为arm linux gcc编译过的运行文件是不能在x86平台上跑的,而且x86armapache能互相startstop,由此断定肯定是安装出错了, 无奈下我全把所有安装文件全删了,重新再来一遍,但我把x86 apache安装包备份了,事实上,x86 的apache里面有一个httpd文件在安装armphp时需要用到,由此建议make install后把安装包备份,然后删掉)

     

     

     

     

    Arm编译:

    新建一个文件夹,用来存放apache for arm

    mkdir  /usr/local/apache_1.3.39_arm

    tar xvf apache_1.3.39.tar.gz -C apache_1.3.39_arm

    cd /usr/local/apache_1.3.39_arm/apache_1.3.39

    CC=arm-linux-gcc ./configure --prefix=/usr/local/apache_arm/apache --enable-module=so 

    出错:

     

    提示testfunc不能打开二进制文件,因为交叉编译的生成的testfunc这个工具不能在PC上执行,可以不理会它。

     

    接着修改一个配置文件,使用上面pc机编译过的文件,

    打开/usr/local/apache_1.3.39_arm/apache_1.3.39/src/main/Makefile这个文件,找 到 这 两 段 代 码

     

    uri_delims.h

    : gen_uri_delims 

    ./gen_uri_delims >uri_delims.h 

    test_char.h

    : gen_test_char 

    ./gen_test_char >test_char.h 

    修改为

     

    uri_delims.h: gen_uri_delims 

    /usr/local/apache_1.3.39/src/main/gen_uri_delims >uri_delims.h 

    test_char.h: gen_test_char 

    /usr/local/apache_1.3.39/src/main/gen_test_char >test_char.h 

    这里借用了刚才编译生成的本机代码里的工具

     

    Make,出错,修改arm-linux-gcc里的stdio.h,找到getlline函数,把名字替换成parseline,保存,再make,ok,编译成功

    再make install ,没问题了,然后记得把parseline函数改回getline

     

    这样,apache for arm就安装结束了,将apache_arm打包到开发板的/usr/local,运行,应该是没有问题了。

     

    PHP编译安装(保证apache没有问题的前提下):

    X86版:

    cd /usr/llocal

    tar -jxvf php-4.4.8.tar.bz2

    cd ./php-4.4.8/

     

    ./configure

    出错:

    configure: error: cannot find output from lex; giving up

     

    apt-get install flex

     

    再次./configure可以了,make,也没有问题

     

    ARM版:

    cd /usr/llocal

    mkdir /usr/local/php-4.4.8_arm

    tar -jxvf php-4.4.8.tar.bz2 -C php-4.4.8_arm

    cd ./php-4.4.8_arm/php-4.4.8

     

    CC=arm-linux-gcc ./configure  --prefix=/usr/local/apache_arm/php --with-apxs=/usr/local/apache_arm/apache/bin/apxs

     

    报错:

    Sorry, I was not able to successfully run APXS.  Possible reasons:

     

    1.  Perl is not installed;

    2.  Apache was not compiled with DSO support (--enable-module=so);

    3.  'apxs' is not in your path.  Try to use --with-apxs=/path/to/apxs

    The output of /usr/local/apache-arm11/apache/bin/apxs follows

    Use of assignment to $[ is deprecated at /usr/local/apache-arm11/apache/bin/apxs line 86.

    /usr/local/apache-arm11/apache/bin/httpd: /usr/local/apache-arm11/apache/bin/httpd: cannot execute binary file

    apxs:Error: Sorry, no DSO support for Apache available

    apxs:Error: under your platform. Make sure the Apache

    apxs:Error: module mod_so is compiled into your server

    apxs:Error: binary `/usr/local/apache-arm11/apache/bin/httpd'.

    configure: error: Aborting

     

     

     

    解决方法:

    在/usr/local/php-4.4.8_arm/php-4.4.8/configure找到checking for Apache 1.x module support via DSO through APXS,把下面的代码注释掉

     

    #  $APXS -q CFLAGS >/dev/null 2>&1

    #  if test "$?" != "0"; then

    #    echo "$ac_t""" 1>&6

    #    echo "$ac_t""" 1>&6

    #    echo "$ac_t""Sorry, I was not able to successfully run APXS.  Possible reasons:" 1>&6

    #    echo "$ac_t""" 1>&6

    #    echo "$ac_t""1.  Perl is not installed;" 1>&6

    #    echo "$ac_t""2.  Apache was not compiled with DSO support (--enable-module=so);" 1>&6

    #    echo "$ac_t""3.  'apxs' is not in your path.  Try to use --with-apxs=/path/to/apxs" 1>&6

    #    echo "$ac_t""The output of $APXS follows" 1>&6

    #    $APXS -q CFLAGS

    #    { echo "configure: error: Aborting" 1>&2; exit 1; } 

    #  fi 

     

    搜索can not run test program while cross compiling,会搜索到很多个这样的结果:
    { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; }
    把它们都改为
    { echo "configure: error: can not run test program while cross compiling" 1>&2; }
    这样做的目的是直接无视交叉编译测试程序错误。

     

    ./config没问题了

     

    Make

    出错:

    In file included from /usr/local/php-4.4.8-arm/php-4.4.8/sapi/apache/sapi_apache.c:24:0:

    /usr/local/php-4.4.8-arm/php-4.4.8/sapi/apache/php_apache_http.h:22:19: fatal error: httpd.h: No such file or directory

    compilation terminated.

    make: *** [sapi/apache/sapi_apache.lo] Error 1

     

     

     

    解决方法:

    使用PC机编译的PHP文件

    gedit /usr/local/php-4.4.8_arm/php-4.4.8/Makefile

     

    install-pear-packages: $(top_builddir)/sapi/cli/php

    @$(top_builddir)/sapi/cli/php $(PEAR_INSTALL_FLAGS) /usr/local/php-4.4.8-arm/php-4.4.8/pear/install-pear.php -d "$(peardir)" -b "$(bindir)" /usr/local/php-4.4.8-arm/php-4.4.8/pear/packages/*.tar

     

     

    修改为:

     : /usr/local/php-4.4.8/sapi/cli/php

    @/usr/local/php-4.4.8/sapi/cli/php $(PEAR_INSTALL_FLAGS) /usr/local/php-4.4.8-arm/php-4.4.8/pear/install-pear.php -d "$(peardir)" -b "$(bindir)" /usr/local/php-4.4.8-arm/php-4.4.8/pear/packages/*.tar

     

     

    并修改相应头文件的绝对路径,不然会提示某些头文件找不到

    gedit /usr/local/php-4.4.8_arm/php-4.4.8/sapi/apache/mod_php4.c

    #include "/usr/local/apache-arm11/apache/include/http_conf_globals.h"

     

    gedit /usr/local/php-4.4.8_arm/php-4.4.8/sapi/apache/php_apache_http.h

    #include "/usr/local/apache_arm/apache/include/httpd.h"

    #include "/usr/local/apache_arm/apache/include/http_config.h"

    # include "/usr/local/apache_arm/apache/include/ap_compat.h"

    #include "/usr/local/apache_arm/apache/include/http_core.h"

    #include "/usr/local/apache_arm/apache/include/http_main.h"

    #include "/usr/local/apache_arm/apache/include/http_protocol.h"

    #include "/usr/local/apache_arm/apache/include/http_request.h"

    #include "/usr/local/apache_arm/apache/include/http_log.h"   

    #include "/usr/local/apache_arm/apache/include/util_script.h"

     

    反正是缺什么补什么,那些头文件都在/usr/local/apache_arm/apache/include里

    Make终于可以了:如下

    Build complete.

    (It is safe to ignore warnings about tempnam and tmpnam).

     

     

    Make install

    出错:

    root@Da:/usr/local/php-4.4.8_arm/php-4.4.8# make install

    Installing PHP SAPI module:       apache

    Use of assignment to $[ is deprecated at /usr/local/apache_arm/apache/bin/apxs line 86.

    /usr/local/apache_arm/apache/bin/httpd: /usr/local/apache_arm/apache/bin/httpd: cannot execute binary file

    apxs:Error: Sorry, no DSO support for Apache available

    apxs:Error: under your platform. Make sure the Apache

    apxs:Error: module mod_so is compiled into your server

    apxs:Error: binary `/usr/local/apache_arm/apache/bin/httpd'.

    make: *** [install-sapi] Error 1

     

    apache_arm/apache/bin/httpd是运行在arm平台上的,当然不能在x86上跑,明白这点,果断把一开始安装的x86 apachehttpd拷贝过来,不要忘记,备份好armhttpd,安装完后还要覆盖回来,我当初就是由于忘了覆盖回来,打包好的安装文件在6410上运行,结果报错如下:

    输入/usr/local/apache-arm11/apache/bin/apachectl start

    报错:

    /usr/local/apache_arm/apache/bin/httpd: line1: elf: not found

    /usr/local/apache_arm/apache/bin/httpd: line2: syntax error: unexpected ”(”

    明显,这个是x86httpd当然也不能在arm平台上跑,绕的路真是太多了。

     

    再次make install,还是不行,报错如下

    make[1]: *** No rule to make target `usr/local/php-4.4.8/sapi/cli/php', needed by `install-pear-packages'.  Stop.

    make: *** [install-pear] Error 2

     

    usr/local/php-4.4.8/sapi/cli/php,奇葩错误,usr前竟然少了个/,没办法,gedit /usr/local/php-4.4.8-arm/php-4.4.8/Makefile改回来,再次maike install,出现

    Php cannot execute binary file,把usr/local/php-4.4.8/sapi/cli/php拷贝到php-4.4.8_arm

    /php-4.4.8/sapi/cli/里,注意备份phpmake install,成功,同理,把备份的armphp拷贝回来,不然在开发板上也是跑不了的。

     

    这就是apache+php全部的移植过程

    剩下的就是如何修改配置文件将apachephp关联起来,百度一搜大把,前辈们还是很给力的,我就不写了。之所以要写这一篇文章,一是记录,二是网上的教程太多太乱,遇到的问题也因人而异,当然,这文章记录的问题也不一定每个人都会遇到,而遇到的问题这篇文章也不一定有,但我想说的是,无论遇到什么问题,不要放弃,耐心分析,善于百度,问题总可以解决的。

     

     

    移植过程主要参考

    http://wenku.baidu.com/link?url=JsY6Daj0RkRAX86IxAA3iHBAtBi2NBqcV6Kp1M1Z9QU0getIQ1tvotWjLWaevkUHBeqKrhC_6IhoQyFBE5PAk2xFePNKD6BWJuhwA-Opa47

    以及大量的博客

     

    另外,转载请指明出处:http://www.cnblogs.com/wupengda/p/4720555.html

     

    今后,还会写上加入sqlite的移植经验。

  • 相关阅读:
    CodeForces Gym 100935G Board Game DFS
    CodeForces 493D Vasya and Chess 简单博弈
    CodeForces Gym 100935D Enormous Carpet 快速幂取模
    CodeForces Gym 100935E Pairs
    CodeForces Gym 100935C OCR (水
    CodeForces Gym 100935B Weird Cryptography
    HDU-敌兵布阵
    HDU-Minimum Inversion Number(最小逆序数)
    七月馒头
    非常可乐
  • 原文地址:https://www.cnblogs.com/wupengda/p/4720555.html
Copyright © 2011-2022 走看看