基于arm-linux-gcc的Apache和PHP移植

当Web 2.0在网络上大行其道的时候,嵌入式领域还少有耳闻,既然目前我们已经有了差距,那么还是再向前跨一步,希望可以借助Web 2.0的技术走在同行的前面。本打算使用Ajax+Apache+CGI来做初步尝试,但思来想去,还是决定再“勇猛”一点,放弃CGI,尝试PHP,虽然在ARM上使用PHP已不是什么新鲜事,但对于我来说还是个不小的挑战。 

用arm-linux-gcc移植Apache和PHP的过程,参考了很多博文,很感谢各位前辈的无私分享。Let's go!

 

Apache

本打算使用Apache2.2.17来移植,但相对于我们可怜的Memory来说有点奢侈,所以最终还是选择了1.3.39。编译过程分为两个过程:本机编译和交叉编译。这是因为在交叉编译时,后续的编译过程要使用到开始阶段编译的工具,而交叉编译的工具无法在PC上运行,因此需要借助本机gcc编译的工具来替换从而完成交叉编译的过程。

编译之前,将Apache解压缩到/home/aifler下两份,一个叫做apache_1.3.39,另一个叫做apache_1.3.39_arm

 

1. 本机编译

  • $ cd /home/aifler/apache_1.3.39
  • ./configure
  • $ make

执行完make后就完成本机编译了,生成了我们需要使用的编译工具。

我使用的是Ubuntu 9.04,在本机编译中经遇到一个问题,configure时会报出以下错误而暂停。

Configuring for Apache, Version 1.3.39
+ Warning: Your ‘echo’ command is slightly broken.
+ It interprets escape sequences per default. We already
+ tried ‘echo -E’ but had no real success. If errors occur
+ please set the SEO variable in ‘configure’ manually to
+ the required ‘echo’ options, i.e. those which force your
+ ‘echo’ to not interpret escape sequences per default.
+ using installation path layout: Apache (config.layout)
Creating Makefile
Creating Configuration.apaci in src
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

 

2. 交叉编译

  • cd /home/aifler/apache_1.3.39_arm
  • CC=arm-linux-gcc ./configure --prefix=/usr/local/apache
  • 将/home/aifler/apache_1.3.39_arm/src/main/Makefile做如下修改:
    uri_delims.h: gen_uri_delims
    ./gen_uri_delims >uri_delims.h
     /home/aifler/apache_1.3.39/src/main/gen_uri_delims >uri_delims.h
    test_char.h: gen_test_char
    ./gen_test_char >test_char.h
     /home/aifler/apache_1.3.39/src/main/gen_test_char >test_char.h
  • $ make
  • $ sudo make install 切换到root用户的原因是之前configure时配置的安装路径在/usr下

执行完上述过程后,交叉编译好的Apache就存在/usr/local下的apache中。其中需要注意,因为Aapche不支持root用户,所以需要确认ARM Linux文件系统中有nobody组和nogroup组。之后,我们将apache放到ARM Linux文件系统中同样的的位置/usr/local/apache下,执行下面的命令启动Apache

  • $ cd /usr/local/apache/bin
  • $ ./apachectl start

 

3. 测试

假设ARM板的IP地址为192.168.1.2,Aapche的默认端口为8080,所以在浏览器中输入http://192.168.1.2:8080,能够看到默认的测试页面,就说明Apache运行正常了。

 

PHP

由于我们需要用到PHP5的一些新的特性,所以使用了php 5.3.6作为移植源码包。需要准备的源码包有三个:php-5.3.6.tar.bz2,libxml2-2.6.26.tar.gz,zlib-1.2.3.tar.bz2,这里不提供下载地址了,google一下就什么都有了基于arm-linux-gcc的Apache和PHP移植...

 

1. 交叉编译libxml2和zlib,扩展arm-linux-gcc的lib库

  • 解压缩libxml2-2.6.26.tar.gz到/home/aifler下
    $ cd /home/aifler/libxml2-2.6.26
    $ CC=arm-linux-gcc ./configure --host=arm-linux --prefix=/usr/local/arm/3.4.1/arm-linux
    $ make
    $ sudo make install
  • 解压缩zlib-1.2.3.tar.bz2到/home/aifler下
    $ cd /home/aifler/zlib-1.2.3
    $ CC=arm-linux-gcc ./configure --prefix=/usr/local/arm/3.4.1/arm-linux
    $ make
    $ sudo make install

 

2. 交叉编译PHP

  • 解压缩php-5.3.6.tar.bz2到/home/aifler下
    $ cd /home/aifler/php-5.3.6
    $ CC=arm-linux-gcc ./configure --host=arm-linux --prefix=/usr/local/php --disable-all --enable-pdo --with-sqlite --with-zlib --without-iconv
    $ make
    $ sudo make install
  • $ sudo -s
    # cp php.ini-development /usr/local/php/lib
    # mv /usr/local/php/lib/php.ini-development /usr/local/php/lib/php.ini
  • # cd /usr/local/php/bin
    # arm-linux-strip php
    # arm-linux-strip php-cgi

执行完上述过程后,交叉编译好的HPH就存在/usr/local下的php中。

 

3. 配置Apache

编辑apache/conf/httpd.conf,在相应的地方添加下面的语句:

DirectoryIndex index.php
DirectoryIndex index.php3
DirectoryIndex index.phtml
ScriptAlias /php5/ "/usr/local/php/bin/"
AllowOverride None
Options None
Order allow,deny
Allow from all
AddType  application/x-httpd-php .php3
AddType application/x-httpd-php .php
AddType application/x-httpd-php .phtml
Action application/x-httpd-php "/php5/php-cgi"

 

4.测试

将php文件夹传到ARM板的相同位置/usr/local/php,写一个"Hello wrold!"的test.php放到设置的"DocumentRoot"中,在浏览器中输入http://192.168.1.2:8080/test.php,能够看到"Hello wrold!",就说明PHP5运行成功了。


虽然,Apache和PHP移植成功,但实际的执行效率还有待测试,当然鉴于功能需求,还需要对其进行裁剪或者其他版本的移植。套用一句广告语:成功,我才刚上路呢...

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值