Apache移植到ARM

来源:互联网 发布:淘宝家乡版是什么意思 编辑:程序博客网 时间:2024/05/20 02:22
1. Download the Apache HTTP Server 
   进入http://httpd.apache.org/download.cgi, 下载httpd-2.4.12.tar.gz源码。
   
   Download the Apache Portable Runtime 1.5.2 // 即apr
   进入http://apr.apache.org/, 下载 Apache Portable Runtime 1.5.2 Released
   
   Download the Apache Portable Runtime Utility 1.5.4 // 即apr-util
   进入http://apr.apache.org/, 下载 Apache Portable Runtime Utility 1.5.4 Released
   
   Download PCRE  // Perl Compatible Regular Expressions
   进入http://www.pcre.org/, 下载pcre-8.37.tar.gz
   
   注意:如果要编译httpd-2.4.13必须需要apr、apr-util和pcre的支持。
   在http://httpd.apache.org/docs/2.4/install.html, 中有详细介绍,拷贝如下:
   The following requirements exist for building Apache httpd:
   
   APR and APR-Util
       Make sure you have APR and APR-Util already installed on your system. 
       If you don't, or prefer to not use the system-provided versions, 
       download the latest versions of both APR and APR-Util from Apache APR, 
       unpack them into /httpd_source_tree_root/srclib/apr and 
       /httpd_source_tree_root/srclib/apr-util (be sure the directory names do 
       not have version numbers; for example, the APR distribution must be 
       under /httpd_source_tree_root/srclib/apr/) and use ./configure's 
       --with-included-apr option. On some platforms, you may have to install 
       the corresponding -dev packages to allow httpd to build against your 
       installed copy of APR and APR-Util.
       
   Perl-Compatible Regular Expressions Library (PCRE)
       This library is required but not longer bundled with httpd. Download the 
       source code from http://www.pcre.org, or install a Port or Package. If 
       your build system can't find the pcre-config script installed by the PCRE
       build, point to it using the --with-pcre parameter. On some platforms, 
       you may have to install the corresponding -dev package to allow httpd to
       build against your installed copy of PCRE.


2. 将上述4个源代码放入的的Linux主机任意目录下,分别按如下方式解压
   tar xzvf httpd-2.4.12.tar.gz // 解压httpd-2.4.12到当前目录
   tar xzvf pcre-8.37.tar.gz    // 解压pcre-8.37.tar.gz到当前目录
   tar xzvf apr-1.5.2.tar.gz -C httpd-2.4.12/srclib/
   tar xzvf apr-util-1.5.4.tar.gz -C httpd-2.4.12/srclib/
   将apr和apr-util解压到httpd的srclib目录下,上面有介绍这种使用方法,也可独立
   编译,原理一样,这里不做详细介绍(可参考pcre的编译)。
   
3. cd httpd-2.4.12/srclib/    // 进入srclib目录
   mv apr-1.5.2 apr           // 修改文件夹名称,上述有介绍
   mv apr-util-1.5.4 apr-util // 修改文件夹名称,上述有介绍
   
4. 因为编译过程中会执行某些可执行程序,而我们现在是交叉编译。所以需要先在Linux
   主机进行非交叉编译,将生成的可执行文件暂存到其他目录;当进行交叉编译时,再拷
   贝到相应的目录去执行。
   
   a. pcre
   
   进入pcre-8.37目录,执行mkdir my_install, 创建pcre的安装目录。
   CFLAGS="-g -O2" ./configure --prefix=/home/huyubin/zynq/apache/test/pcre-8.37/my_install/
   其中 “/home/huyubin/zynq/apache/test/”为主机系统的绝对路径。
   
   make
   
   make install
   
   b. httpd
   进入httpd-2.4.12目录
   CFLAGS="-g -O2" LIBS=-L/home/huyubin/zynq/apache/test/pcre-8.37/my_install/lib 
   ./configure --with-included-apr ac_cv_file__dev_zero=yes 
   ac_cv_func_setpgrp_void=yes 
   apr_cv_tcp_nodelay_with_cork=yes ac_cv_sizeof_struct_iovec=8 
   ap_cv_void_ptr_lt_long=4 --with-pcre=../pcre-8.37/my_install
   
   make
   
   c. 在/home/huyubin/zynq/apache/test/目录下新建2个文件夹   
   mkdir pc-httpd
   mkdir pc-apr
   将b过程生成的httpd-2.4.12/server/gen_test_char拷贝到pc-httpd目录下,备用。
   将b过程生成的httpd-2.4.12/srclib/apr/tools/gen_test_char拷贝到pc-apr目录下,备用。
   注意:这2个可执行文件仅名字相同,实际功能是不一样的注意别弄混了。
   cp httpd-2.4.12/server/gen_test_char pc-httpd/
   cp httpd-2.4.12/srclib/apr/tools/gen_test_char pc-apr/
   
   d. 清除在主机的编译安装文件
   
   进入pcre-8.37目录,执行如下命令
   make uninstall
   make distclean
   
   进入httpd-2.4.12目录,执行如下命令
   make distclean   
   
5. 交叉编译pcre
   进入pcre-8.37目录,执行如下命令
   CC=/usr/local/arm/arm-xilinx/lin/bin/arm-xilinx-linux-gnueabi-gcc 
   CXX=/usr/local/arm/arm-xilinx/lin/bin/arm-xilinx-linux-gnueabi-g++ 
   CFLAGS="-g -O2" ./configure --prefix=/home/huyubin/zynq/apache/test/pcre-8.37/
   my_install/ --host=arm-xilinx-linux-gnueabi
   其中CC=“你的C交叉编译器” , CXX=“你的C++交叉编译器”,--prefix=“安装路径”,
   --host="交叉编译的目标板系统"
   
   make 
   
   make install
   
6. 交叉编译httpd、apr和apr-util


   新建httpd安装文件夹
   mkdir -p /mnt/ram/apache
   注意此目录最好是和目标板名字相同的路径,因为httpd运行时会使用安装目录。
   
   进入httpd-2.4.12目录,执行如下命令
   CC=/usr/local/arm/arm-xilinx/lin/bin/arm-xilinx-linux-gnueabi-gcc 
   CXX=/usr/local/arm/arm-xilinx/lin/bin/arm-xilinx-linux-gnueabi-g++ 
   CFLAGS="-g -O2 -lpthread" LIBS=-L/home/huyubin/zynq/apache/test/pcre-8.37/
   my_install/lib ./configure --prefix=/mnt/ram/apache/ --with-included-apr 
   ac_cv_file__dev_zero=yes ac_cv_func_setpgrp_void=yes 
   apr_cv_tcp_nodelay_with_cork=yes ac_cv_sizeof_struct_iovec=8 
   ap_cv_void_ptr_lt_long=4 apr_cv_process_shared_works=yes 
   apr_cv_mutex_robust_shared=yes --with-pcre=../pcre-8.37/my_install 
   --host=arm-xilinx-linux-gnueabi cross_compiling=yes --with-mpm=prefork
   
   make  // 提示 tools/gen_test_char > include/private/apr_escape_test_char.h
            /bin/sh: tools/gen_test_char: cannot execute binary file
   cp ../pc-apr/gen_test_char srclib/apr/tools  // 拷贝到apr中
   
   make  // 提示 ./gen_test_char > test_char.h
                 /bin/sh: ./gen_test_char:cannot execute binary file
   cp ../pc-httpd/gen_test_char server/      // 拷贝到httpd中
   make
   sudo make install
   
7. 进入安装目录/mnt/ram/apache,可以看到bin、build、cgi-bin、conf、error、
   htdocs、icons、include、lib、logs、man、manual和moudles
   
   将bin、cgi-bin、conf、error、htdocs、lib、logs、和moudles通过FTP或者其他方式,
   传输到目标板的/mnt/ram/apache/路径下。同样也将主机上pcre-8.37/my_install/lib中
   的所有静态库和动态库上传到目标板的/mnt/ram/apache/lib目录中。
   
   由于apache/lib目录下的库包含软连接,无法将软连接上传到目标板,所以需要在目标板
   上重新建立软连接。
   进入目标板的/mnt/ram/apache/lib, 执行如下脚本或者手动建立软连接。
   #!/bin/sh
   ln -s libapr-1.so.0.5.2 libapr-1.so
   ln -s libapr-1.so.0.5.2 libapr-1.so.0
   ln -s libaprutil-1.so.0.5.4 libaprutil-1.so
   ln -s libaprutil-1.so.0.5.4 libaprutil-1.so.0
   ln -s libexpat.so.0.5.0 libexpat.so
   ln -s libexpat.so.0.5.0 libexpat.so.0
   ln -s libpcrecpp.so.0.0.1 libpcrecpp.so
   ln -s libpcrecpp.so.0.0.1 libpcrecpp.so.0
   ln -s libpcreposix.so.0.0.3 libpcreposix.so
   ln -s libpcreposix.so.0.0.3 libpcreposix.so.0
   ln -s libpcre.so.1.2.5 libpcre.so
   ln -s libpcre.so.1.2.5 libpcre.so.1
   
8. 在目标板上建立daemon组和daemon用户,并将用户daemon加入到daemon组。
   addgroup daemon
   adduser -G daemon daemon
   或者执行如下脚本:
   #!/bin/sh
   addgroup daemon
   (echo "123456"
   sleep 1
   echo "123456")|adduser -G daemon daemon
   
9. 修改目标板上的/mnt/ram/apache/conf/httpd.conf文件
   将 #ServerName www.example.com:80 改为
   ServerName localhost:80
   
10.进入目标板上的/mnt/ram/apache/bin目录
   执行 ./apachectl -k start
   
11.此时可以用ps命令查看httpd进程是否已经启动。


12.打开PC端的浏览器,输入目标板的IP地址。即可显示
    It works!
    
13. 至此apache移植完成。
0 0