基于arm-linux-gcc的Apache和PHP移植
来源:互联网 发布:尼康中国倒闭 知乎 编辑:程序博客网 时间:2024/05/29 19:35
此文从新浪博客搬家至CSDN,原文作于2011年5月。
当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一下就什么都有了...
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移植成功,但实际的执行效率还有待测试,当然鉴于功能需求,还需要对其进行裁剪或者其他版本的移植。套用一句广告语:成功,我才刚上路呢...
- 基于arm-linux-gcc的Apache和PHP移植
- 基于arm-linux-gcc的Apache和PHP移植
- 基于ARM的Apache服务器移植
- 基于ARM LINUX的嵌入式GUI的研究和移植
- arm-linux-gcc 和gcc的问题
- 基于PXA255的ARM Linux操作系统移植
- arm-linux-gcc 和 arm-elf-gcc 的区别
- arm-linux-gcc和arm-elf-gcc的区别
- arm-linux-gcc和arm-elf-gcc的区别
- arm-linux-gcc 和 arm-elf-gcc 的区别
- arm-linux-gcc 和 arm-elf-gcc 的区别
- arm-linux-gcc的安装和配置
- 基于ARM-LINUX的PHP应用
- 基于ARM-LINUX的PHP应用
- 简单说明gcc和arm-linux-gcc的区别
- 浅析gcc、arm-linux-gcc和arm-elf-gcc的关系
- 浅析gcc、arm-linux-gcc和arm-elf-gcc的关系
- 浅析gcc、arm-linux-gcc和arm-elf-gcc的关系
- uva 10054 The Necklace (欧拉回路)
- 使用Xshell连接服务器SSH
- 【Eclipse提高开发速度-插件篇】Checkstyle的使用
- linux系统启动流程
- TO_CHAR(DATE,FORMAT)用法
- 基于arm-linux-gcc的Apache和PHP移植
- 世俗人生,匆匆步履
- linux下C实现IP地址,DNS,网关的自动获取
- [.Net防止反编译].NET 产品版权保护方案 (.NET源码加密保护)
- 基础总结篇:ContentProvider之读写联系人
- Qt中提高SQLite的读写速度
- hdu 1690 Bus System 最短路(dijkstra+floyd)
- java初学者感想五
- c语言字符串 数字转换函数大全