目標(biāo):靜態(tài)編譯
版本:apache-1.3.39 + php-5.5.5
PC環(huán)境:ubuntu16
交叉編譯工具鏈:arm-linux-gcc
首先可以參考:https://www.cnblogs.com/eoiioe/archive/2008/12/23/1360476.html,按照這樣的思路進(jìn)行。
一 . 編譯apache
首先參考:
http://blog.sina.com.cn/s/blog_7f0a98c40100rxdz.html
https://www.veryarm.com/42263.html
http://www.linuxdown.net/command/2017/1219/16733.html
編譯apache,需要分別用到本機(jī)編譯和交叉編譯,這里解壓apache-1.3.39.tar.gz到兩個(gè)文件夾,這兩個(gè)文件夾分別為arm和pc。

1.本機(jī)編譯。
進(jìn)入到 pc/src目錄下執(zhí)行 ./Configure 命令,生成Makefile文件。
返回到 pc目錄下,執(zhí)行 ./configure命令,然后 make,這里不需要make install.
因?yàn)樵诮徊婢幾g的時(shí)候,只需要用到主機(jī)編譯的在 pc/src/main 目錄下生成的兩個(gè)可執(zhí)行文件,分別為gen_test_char 和 gen_uri_delims。
2.交叉編譯
配置自己的交叉編譯工具鏈環(huán)境,在添加到/etc/profile后source一下,終端測試arm-linux-gcc -v,返回該交叉編譯鏈的具體信息,再export CC=arm-linux-gcc即可(該shell命令可直接寫在/etc/profile中,不用在終端輸出了),然后步驟依然同上:
進(jìn)入到 arm/src目錄下執(zhí)行 ./Configure 命令,生成Makefile文件。
返回到 arm目錄下,執(zhí)行 ./configure命令, 其配置選項(xiàng)如下:
#!/bin/sh
./configure \
--prefix=/mnt/nand1-2/apache \
--enable-module=most \
--enable-module=rewrite
這里可參考
https://blog.csdn.net/yinzhipeng123/article/details/53044998
https://my.oschina.net/xiangpang/blog/535565?p={{currentPage+1}}
這里可能會報(bào)錯(cuò),有

或者
/home/f/下載/Apache/arm/src/helpers/testfunc: 1: Syntax error: word unexpected (expecting ")")
/home/f/下載/Apache/arm/src/helpers/testfunc: 1: Syntax error: word unexpected (expecting ")")
/home/f/下載/Apache/arm/src/helpers/testfunc: 1: Syntax error: word unexpected (expecting ")")
/home/f/下載/Apache/arm/src/helpers/testfunc: 1: Syntax error: word unexpected (expecting ")")
/home/f/下載/Apache/arm/src/helpers/testfunc: 1: Syntax error: word unexpected (expecting ")")
這里將 pc/src/main/下的上面所說的兩個(gè)可執(zhí)行文件復(fù)制(也說覆蓋)到arm/src/main/下,然后再進(jìn)行make即可,若再次出現(xiàn)同樣的錯(cuò)誤,可再次進(jìn)行同樣的復(fù)制操作,再make。(注,make規(guī)則中如果依賴文件中任一個(gè) 文件的時(shí)間戳比目標(biāo)文件新,則使用規(guī)則所定義的命令重建目標(biāo)文件。)
在make過程中,可能有

這里找到對應(yīng)文件,注釋掉相應(yīng)選項(xiàng)再次make即可。


無需make install,進(jìn)行第二步。
二 .交叉編譯php
- 為實(shí)現(xiàn)靜態(tài)編譯,這里需要提前安裝php所需要的靜態(tài)庫,這里我安裝了5種靜態(tài)庫文件,分別使用了libxml2-2.9.2, openssl-1.0.2q, zlib-1.2.8, libiconv-1.14, pcre-7.8, 安裝的路徑可自定義,但盡量安裝到一個(gè)主文件路徑下,如默認(rèn)的 /usr/local/ 。另外,由于php5以上版本默認(rèn)支持sqlite選項(xiàng),因此這里就不在配置了。
關(guān)于./configure配置選項(xiàng)我寫在go.sh文件里面了,該文件內(nèi)容如下,執(zhí)行時(shí)給文件 chmod+x 即可。
#! /bin/sh
./configure \
--host=arm-linux \
--prefix=/mnt/nand1-2/php \
--enable-shared=no \
--disable-shared \
--with-apache=/home/f/下載/Apache/arm \
--enable-static=yes \
--enable-sockets \
--disable-all \
--enable-pdo \
--enable-json \
--disable-ipv6 \
--enable-sqlite-utf8 \
--with-libxml-dir=/usr/local/libxml2 \
--with-openssl-dir=/usr/local/openssl/include/openssl \
--with-zlib-dir=//home/f/downloads/NewPHP/zlib \
--with-iconv-dir=/home/f/downloads/NewPHP/libiconv \
--with-pcre-dir=/home/f/downloads/NewPHP/pcre
#--with-sqlite3=/usr/local/sqlite3\lib\libsqlite3.a \
#--with-pdo-sqlite \
#--enable-sqlite3 \
- 這里必須配置--with-apache,生成apache 所load的靜態(tài)庫文件,后面跟的路徑就是上面apache解壓編譯所在的路徑(arm文件夾路徑)。
- 上述配置只是編譯靜態(tài)庫文件 .a ,我們還需要生成靜態(tài)可執(zhí)行文件 statically linked
參考:http://ju.outofmemory.cn/entry/119804
這里在makefile中,更改:
-o 前面加上-all-static
-
make,該過程可能會出現(xiàn)下面錯(cuò)誤
TIM截圖20190830181533.png
這里只需要定位到文件,然后將這個(gè)預(yù)編譯選項(xiàng)注釋掉即可。make成功后,可以看到在文件夾下,php解壓編譯文件夾下libs文生成了libphp5.a文件和libphp5.la文件,而且在對應(yīng)的apache解壓編譯文件夾arm下的src/modules/php5頁生成了相應(yīng)的文件,我們第三步的activate路徑就是從這取。
-
make install ,可以看到安裝目錄/mnt/nand1-2/php下面有bin文件夾有php、php-cgi文件,有
TIM截圖20190830191713.png
成功編譯靜態(tài)庫和靜態(tài)可執(zhí)行文件。當(dāng)然這兩個(gè)靜態(tài)可執(zhí)行文件內(nèi)存有點(diǎn)大,用arm-linux-strip一下即可。
6.復(fù)制編譯目錄下的php.oni-development到安裝目錄/mnt/nand1-2/php/lib下,并改名php.ini。
三 .再次編譯apache,跟第一步動作類似。
但是:
- 當(dāng)再次在arm文件夾下進(jìn)行./configure配置,有
#!/bin/sh
./configure \
--prefix=/mnt/nand1-2/apache \
--activate-module=src/modules/php5/libmodphp5.a
--enable-module=most \
--enable-module=rewrite
2.上面一步是添加php配置選項(xiàng),以及表示靜態(tài)編譯的方式,鏈接現(xiàn)有的靜態(tài)庫文件,以后不加載任何動態(tài)模塊,而這一步需要進(jìn)行生成apache靜態(tài)可執(zhí)行文件的設(shè)置。
在arm/src文件夾下的Makefile中,下面圖中在 -o 符號之前添加 -static 選項(xiàng)

在arm/src/support文件夾下的Makefile中,下面圖中在 -o 符號之前添加 -static 選項(xiàng)

3.如果跟第一步報(bào)同樣的錯(cuò),按第一步的規(guī)則處理,在arm文件夾下執(zhí)行make,然后make install安裝。
四 .此時(shí)在/mnt/nand1-2/文件夾下已經(jīng)有兩個(gè)最終安裝后的apache和php文件夾。在將兩者復(fù)制到開發(fā)板同樣的位置,并使用,還得配置http.conf文件。
# 首先是基本的配置
Listen 0.0.0.0:80
Port 80
User nobody
Group nogroup
ServerName localhost
#然后
#205行
# Note: The order in which modules are loaded is important. Don't change
# the order below without expert advice.
# Example:
# LoadModule foo_module libexec/mod_foo.so
####這里不需要?jiǎng)討B(tài)加載php動態(tài)庫文件,因?yàn)槲覀冃枰o態(tài)編譯
####即無需LoadModule php5_module modules/libphp5.so
# ExtendedStatus controls whether Apache will generate "full" status
#364行
<IfModule mod_dir.c>
DirectoryIndex index.html
DirectoryIndex index.php
DirectoryIndex index.php3
DirectoryIndex index.phtml
</IfModule>
#763行
#
AddType application/x-tar .tgz
AddType application/x-httpd-php .php
AddType application/x-httpd-php .php3
AddType application/x-httpd-php .php5
AddType application/x-httpd-php .phtml
#
# AddEncoding allows you to have certain browsers uncompress
# information on the fly. Note: Not all browsers support this.
# Despite the name similarity, the following Add* directives have nothing
# to do with the FancyIndexing customization directives above.
#
AddEncoding x-compress .Z
AddEncoding x-gzip .gz .tgz
Action application/x-httpd-php "/php5/php-cgi"
由于apache拒絕使用root用戶運(yùn)行,所以需要增加一個(gè)用戶和用戶組,這里使用默認(rèn)的用戶名和用戶組名,nobody和nogroup。
建立文件passwd代替開發(fā)板上的/etc/passwd
root::0:0:root:/:/bin/sh
nobody::65534:65533:nobody:/:/bin/sh
建立文件group代替開發(fā)板上的/etc/group
nobody::65533:
nogroup::65534:nobody
root:x:0:root
users::100:
五. 啟動開發(fā)板,在終端有
mnt/nand1-2/apache/bin/apachectl start
則開發(fā)板上的apache服務(wù)已啟動,下面即可以在主機(jī)通過ip訪問嵌入式web了。

