Apache2.4.12移植

Apache的移植相对比较复杂,首先得移植其依赖的库。其主要的库有pcre,APR(apache 运行时库),APR-util,和zlib库。
下面我们将分别一一移植:
1. PCRE的移植:
该移植比较简单.

 >> ./configure   \
 --prefix='$INSTALLROOT/pcre'  \
 --host=arm-linux    \
 CC=arm-linux-gnueabihf-gcc  \
 CXX=arm-linux-gnueabihf-g++ 

这里的CXX一定要配置,因为它需要用到C++编译器。

>> make && make install

2. APR移植
Apache运行时库的移植很重要,它关系着Apache的运行。

./configure  --prefix='$INSTALLROOT/apr' \ --host=arm-linux        \
CC=arm-linux-gnueabihf-gcc \ 
ac_cv_file__dev_zero=yes \
ac_cv_func_setpgrp_void=yes \ 
apr_cv_tcp_nodelay_with_cork=yes 

①如果不添加ac_cv_file__dev_zero=yes(注意file和dev之间是两个下划线),则会出现:

check for /dev/zero… configure:error:cannot check for file existence
when cross compile

②如果不添加ac_cv_func_setpgrp_void=yes,则会出现:

checking whether setpgrp takes no argument… configure: error: cannot
check setpgrp when cross compiling

make && make install

编译时,会出现下列错误:

./include/apr_want.h:95: error: redefinition of ‘struct iovec’
make[1]: * [passwd/apr_getpass.lo] 错误 1

修改include/apr_want.h,屏蔽掉下面结构体。

/*struct iovec
{
    void *iov_base;
    size_t iov_len;
};*/

编译OK


3. APR-util 移植

./configure --prefix='$INSTALLROOT/apr-util'   \ 
--with-apr='$INSTALLROOT/apr'  \
--host=arm-linux    \
CC=arm-linux-gnueabihf-gcc

一定要指定APR运行时库的路径。

make && make install

4. Zlib 移植:
不交叉编译zlib,会在Apache configure是出错,错误如apache移植中所述。

./configure  --prefix='$INSTALLROOT/zlib'

要想交叉编译zlib,必须修改Makefile,因为其makefile 的编译器为gcc 。故需要将所有的gcc,ld,ar改成交叉编译器(XXX-gcc);

make && make install

编译完成。


5. Apache 移植:
先给出一个样板:

./configure \

> --prefix=/usr/local/apache-2.4.12 \
> --enable-deflate \            #压缩
> --enable-expires \            #缓存
> --enable-headers \
> --enable-modules=most \
> --enable-so \
> --with-mpm=worker \            #worker模型
> --enable-rewrite \             #rewrite重写规则
> --with-apr=/usr/local/apr \
> --with-apr-util=/usr/local/apr-util
> --enable-ssl                    #支持ssl

我们开始编译:

./configure --prefix='/usr/local/apache' \
--host=arm-linux --enable-deflate    \
--enable-expires  --enable-headers   \
--enable-modules=most --enable-so   \
--with-mpm=worker --enable-rewrite  \
--with-apr='$INSTALLROOT/apr'    \
--with-apr-util='$INSTALLROOT/apr-util' \
 --with-pcre='$INSTALLROOT/pcre'   \
 --with-z='$INSTALLROOT/zlib'  \       
 ap_cv_void_ptr_lt_long=no   \
 --enable-ssl  \
 CC=arm-linux-gnueabihf-gcc   \
 LIBS=-lpthread

① 必须指定这三个依赖库的路径,否则,就要将这些库放在Apache目录下。
② Apache的模型一般选用worker模型,当然,你也可以根据需要选择prefork模式。
③如果不添加ap_cv_void_ptr_lt_long=no选项,则会出现:

configure: error: Size of “void *” is less than size of “long”

④一定要添加-lpthread的支持,否则会出现下列错误:

…./arm-linux-gnueabihf/libpthread.so.0: could not read symbols:
Invalid operation

⑤缺少zlib库,安装zlib的步骤如4所示。

checking for zlib location… not found checking whether to enable
mod_deflate… configure: error: mod_deflate has been requested but
can not be built due to prerequisite failures

make && make install

① gen_test_char 不能执行。
要在宿主机上重新编译一遍apache。取出其gen_test_char放到server目录,(为什要这么做? Apache的编译的Makefile不是很好,gen_test_char是要在宿主机上运行的,而make却编译成了target上的可执行程序)。并修改名字为gen_test_char1,同时修改makefile。

test_char.h: gen_test_char
    ./gen_test_char1 > test_char.h

OK,至此没有出错,Apache移植成功!
将其拷贝至相应目录下,并复制相应的动态链接库。
配置httpd.conf文件中的 ServerName如下:

ServerName localhost:80

OK,测试Apache。

apachectl start
apachectl stop

均OK,Apache移植完成!虽然简单,但很费时间(因为至少得照着上面的步骤编译2遍)。

你可能感兴趣的:(应用)