S3C6410移植apache和php

2024-09-18  

需要准备的东西:

Apache-1.3.39 for linux

Php-4.4.8 for linux

Ubuntu amd64位 PC机

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

 

交叉编译:

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

 

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

 

Apache和php安装包放在/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,保存,再make,ok,编译成功,然后记得把parseline函数改回getline

 

Make install也没有问题

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

文章来源于:电子工程世界    原文链接
本站所有转载文章系出于传递更多信息之目的,且明确注明来源,不希望被转载的媒体或个人可与我们联系,我们将立即进行删除处理。