移植 Nginx+PHP(FastCGI) 到 ARM Linux (一)

2019-07-13 06:59发布

环境

交叉编译环境:Ubuntu12.04 64位
交叉编译器:arm-linux-gcc-4.9.x
ARM系统:Linux imx6dlsabresd 3.14.52-1.1.1_ga+gdb1bcba #5 SMP PREEMPT Wed Mar 15 12:15:01 CST 2017 armv7l GNU/Linux

Nginx 交叉编译

1、 预先下载好文件
a,nginx-1.12.1.tar.gz
b,pcre-8.30.tar.gz(不要下最新的pcre2-**.tar.gz)
c,zlib-1.2.11.tar.gz 说明:我这里不需要支持https访问,所以下面不会编译openssl模块。 2、 解压文件 robinson@robinson-vm:~/Downloads/ForTest$ ls nginx-1.12.1.tar.gz pcre-8.30.tar.gz zlib-1.2.11.tar.gz robinson@robinson-vm:~/Downloads/ForTest$ tar -xzvf nginx-1.12.1.tar.gz robinson@robinson-vm:~/Downloads/ForTest$ tar -xzvf pcre-8.30.tar.gz robinson@robinson-vm:~/Downloads/ForTest$ tar -xzvf zlib-1.2.11.tar.gz robinson@robinson-vm:~/Downloads/ForTest$ ls nginx-1.12.1 pcre-8.30 zlib-1.2.11 nginx-1.12.1.tar.gz pcre-8.30.tar.gz zlib-1.2.11.tar.gz 3、 编写configure配置文件脚本nginx_configure.sh #!/bin/sh BUILD_PATH=/home/nginx_arm CC_PATH=/home/robinson/Downloads/gcc-linaro-arm-linux-gnueabihf-4.9-2014.09_linux/bin/arm-linux-gnueabihf-gcc CPP_PATH=/home/robinson/Downloads/gcc-linaro-arm-linux-gnueabihf-4.9-2014.09_linux/bin/arm-linux-gnueabihf-g++ ./configure --prefix=$BUILD_PATH --with-zlib=/home/robinson/Downloads/ForTest/zlib-1.2.11 --with-pcre --with-pcre=/home/robinson/Downloads/ForTest/pcre-8.30 --with-pcre-jit --with-cc=$CC_PATH --with-cpp=$CPP_PATH 说明:
  此脚本文件存放于nginx-1.12.1文件夹下,需要自行添加可执行权限。
  关于BUILD_PATH,这是编译好的nginx存放位置。
  关于CC_PATH、CPP_PATH是交叉编译器路径,这里填的完整路径,如果配置好环境变量可以直接写:arm-linux-gnueabihf-gcc、arm-linux-gnueabihf-g++,大家需要根据自己的实际情况作调整。
  前面提到了我没有配置openssl模块编译。 4、修改几处源代码(nginx-1.12.1文件夹下)
  1). auto/cc/name if [ "$NGX_PLATFORM" != win32 ]; then ngx_feature="C compiler" ngx_feature_name= #ngx_feature_run=yes ngx_feature_run=no ==>set to no to skip check ngx_feature_incs= ngx_feature_path=   2). auto/types/sizeof (1)ngx_test="$CC $CC_TEST_FLAGS $CC_AUX_FLAGS ==> ngx_test="gcc $CC_TEST_FLAGS $CC_AUX_FLAGS (2)checking for $ngx_type size END ngx_size= ==> ngx_size=4   3). auto/lib/pcre/make ./configure --disable-shared $PCRE_CONF_OPT ==>./configure --disable-shared $PCRE_CONF_OPT --host=arm   4). src/os/unix/ngx_errno.h (新增)#define NGX_SYS_NERR 333 (新增)#ifndef NGX_HAVE_SYSVSHM (新增)#define NGX_HAVE_SYSVSHM 1 (新增)#endif typedef int ngx_err_t;   5). src/core/ngx_rwlock.c 12行 #if (NGX_HAVE_ATOMIC_OPS) ==> #if (!NGX_HAVE_ATOMIC_OPS) 5、执行./nginx_configure.sh robinson@robinson-vm:~/Downloads/ForTest/nginx-1.12.1$ sudo ./nginx_configure.sh checking for OS + Linux 3.13.0-32-generic x86_64 checking for C compiler ... found + gcc version: 4.9.2 20140904 (prerelease) (crosstool-NG linaro-1.13.1-4.9-2014.09 - Linaro GCC 4.9-2014.09) checking for gcc -pipe switch ... foundchecking for -Wl,-E switch ... found ******************* ******************* ******************* checking for struct tm.tm_gmtoff ... found checking for struct dirent.d_namlen ... not found checking for struct dirent.d_type ... found checking for sysconf(_SC_NPROCESSORS_ONLN) ... found checking for openat(), fstatat() ... found checking for getaddrinfo() ... found creating objs/Makefile Configuration summary + using PCRE library: /home/robinson/Downloads/ForTest/pcre-8.30 + OpenSSL library is not used + using zlib library: /home/robinson/Downloads/ForTest/zlib-1.2.11 nginx path prefix: "/home/nginx_arm" nginx binary file: "/home/nginx_arm/sbin/nginx" nginx modules path: "/home/nginx_arm/modules" nginx configuration prefix: "/home/nginx_arm/conf" nginx configuration file: "/home/nginx_arm/conf/nginx.conf" nginx pid file: "/home/nginx_arm/logs/nginx.pid" nginx error log file: "/home/nginx_arm/logs/error.log" nginx http access log file: "/home/nginx_arm/logs/access.log" nginx http client request body temporary files: "client_body_temp" nginx http proxy temporary files: "proxy_temp" nginx http fastcgi temporary files: "fastcgi_temp" nginx http uwsgi temporary files: "uwsgi_temp" nginx http scgi temporary files: "scgi_temp" 6、make robinson@robinson-vm:~/Downloads/ForTest/nginx-1.12.1$ sudo make 7、make install robinson@robinson-vm:~/Downloads/ForTest/nginx-1.12.1$ sudo make install 生成的文件在/home/nginx_arm 8、打包交叉编译好的文件 robinson@robinson-vm:/home$ ls nginx_arm robinson robinson@robinson-vm:/home$ sudo tar -jcvf nginx_arm.tar.bz2 nginx_arm/ nginx_arm/ nginx_arm/html/ nginx_arm/html/index.html nginx_arm/html/50x.html nginx_arm/logs/ nginx_arm/sbin/ nginx_arm/sbin/nginx nginx_arm/conf/ nginx_arm/conf/fastcgi_params.default nginx_arm/conf/nginx.conf.default nginx_arm/conf/scgi_params.default nginx_arm/conf/nginx.conf nginx_arm/conf/uwsgi_params.default nginx_arm/conf/fastcgi.conf nginx_arm/conf/koi-utf nginx_arm/conf/mime.types nginx_arm/conf/koi-win nginx_arm/conf/fastcgi.conf.default nginx_arm/conf/fastcgi_params nginx_arm/conf/mime.types.default nginx_arm/conf/uwsgi_params nginx_arm/conf/win-utf nginx_arm/conf/scgi_params robinson@robinson-vm:/home$ ls nginx_arm nginx_arm.tar.bz2 robinson 9、将nginx_arm.tar.bz2拷贝到arm板子上,注意一定要在/home下解压(路径必须和交叉编译时的路径一致) root@imx6dlsabresd:/home# ls nginx_arm root 10、启动nginx root@imx6dlsabresd:/home/nginx_arm# /home/nginx_arm/sbin/nginx 或 root@imx6dlsabresd:/home/nginx_arm# /home/nginx_arm/sbin/nginx -c /home/nginx_arm/conf/nginx.conf 11、测试,用局域网内的浏览器访问Arm板子的ip,看到下面界面,说明nginx移植成功了。
这里写图片描述

后记

友情提示:
su命令会获取root权限但仍使用用户的环境变量。
sudo命令会获取root权限并使用root的环境变量。