php5在arm-linux下的交叉编译步骤

来源:互联网 发布:异次元的狙击手 知乎 编辑:程序博客网 时间:2024/06/05 09:17
    折腾了一周多终于成功交叉编译了php-5.2.9,现在总结一下,希望能给像我一样的菜鸟提供点帮助。步骤如下:
1. 首先交叉编译zlib。
CC=arm-linux-gcc ./configure --sahred --prefix=/usr/local/arm/3.4.1/arm-linux
make&&make install
(一开始我把zlib装在独立的目录下,编译php时在用上--with-zlib选项还是报错,后来直接安装到我交叉编译器目录/usr/local/arm/3.4.1/arm-linux下就不报错了。)
2. 接着交叉编译libxml2。
CC=arm-linux-gcc ./configure --host=arm-linux --prefix=/usr/local/arm/3.4.1/arm-linux
make&&make install
(安装到/usr/local/arm/3.4.1/arm-linux下的原因同上)
3. 交叉编译php-5.2.9。
(1) CC=arm-linux-gcc ./configure --host=arm-linux --prefix=/usr/local/php-arm --disable-all --enable-pdo --with-sqlite --with-pdo-sqlite --with-zlib --without-iconv
(用--with-apxs2选项会报错,所以选择了编译成cgi模式)
(2) make&&make install
(make的时候出现:undefined reference to dlopen、undefined reference to dlclose,解决方法:在makefile中EXTRA_LIBS之后加上-ldl)
(3) 将PHP源码包中php-.ini-dist文件复制到/usr/local/php-arm/lib下并改名为php.ini。
(4) 用arm-linux-strip把bin目录下的php和php-cgi进行strip。
(5) 将php-arm文件件拷贝到arm板上的/usr/local目录下。
(6) 最后修改arm板上apache的配置文件httpd.conf。添加如下语句:
DirectoryIndex index.php
DirectoryIndex index.php3
DirectoryIndex index.phtml

ScriptAlias /php5/ "/usr/local/php-arm/bin/"
# 注意 "/usr/local/php-arm/bin/" 中最后一个"/"不可少
<Directory "/usr/local/php-arm/bin">
        AllowOverride None
        Options None
        Order allow,deny
        Allow from all
    </Directory>

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"

大功告成!在arm上写一个phpinfo测试页面。在浏览器里输入:http://202.115.30.111:8080/test.php(我设置的监听端口为8080),可以看到php相关信息。
(一开始我把pdo、sqlite编译成动态模块,可是在phpinfo下始终看不到pdo、sqlite信息,查看错误日志说是无法加载动态库,动态加载不支持,不知道怎么改,索性将其编译成静态的,一切就ok了)
原创粉丝点击