交叉编译PHP5、Nginx、Squid的详细步骤

交叉编译php5

软件版本:php-5.4.27

依赖库:zlib,libxml2

交叉编译器:arm-hisiv200-linux-gnueabi

  1. 将交叉编译器路径添加到PATH中,
    我的交叉编译器目录为/usr/local/arm-hisiv200-linux/,而交叉编译器在交叉编译器目录的/bin中,在控制台输入

    PATH=$PATH:/usr/local/arm-hisiv200-linux/bin/
    
  2. 首先先交叉编译zlib,进入zlib源码目录。

  3. 执行CC=arm-hisiv200-linux-gnueabi-gcc  ./configure  –shared
     –prefix=ZLIB_PATH(编译成功后的安装路径)
  4. make && make install
  5. 在ZLIB_PATH中会有编译成功后的文件和配置。
  6. 然后交叉编译libxml2,进入libxml2源码目录。
  7. 执行CC=arm-hisiv200-linux-gnueabi-gcc  ./configure
     –host=arm-hisiv200-linux-gnueabi
     –prefix=LIBXML2_PATH(编译成功后的安装路径)
  8. make && make install
  9. 在LIBXML2_PATH中会有编译成功后的文件和配置。
  10. 开始交叉编译php5,进入php5源码目录。
  11. 首先先执行./buildconf  –force,为了防止出现 cp:cannot stat
    ‘sapi/cli/php.1′: No such file or directory
  12. 执行./configure  –host=arm-hisiv200-linux-gnueabi  –enable-shared
     –with-zlib-dir=ZLIB_PATH  –with-libxml-dir=LIBXML2_PATH
     –disable-phar  –with-sqlite  –with-pdo-sqlite  –without-iconv
     –enable-fpm  –prefix=PHP5_PATH
  13. make && make install
  14. 编译好的php程序及配置就在PHP5_PATH中。

(1)安装nginx

CentOS 下编译安装PHP

1.  去php官网下载源码
,我下载使用的版本是(php-5.4.8.tar.gz)

2.  安装环境

yum install xml2

2.  解压到/usr/src目录,执行命令:sudo tar -zxvf php-5.4.8.tar.gz -C
/usr/src

3.执行./configure

–prefix=/usr/local/php

–with-mcrypt=/usr/local/libmcrypt

–with-zlib –enable-mbstring

–with-openssl

–with-mysql

–with-mysqli –with-mysql-sock

–with-gd –with-jpeg-dir=/usr/lib

–with-bz2

–with-pdo-mysql

–with-gettext

–with-curl

–with-pdo-mysql

–enable-sockets

–enable-bcmath

–enable-xml

–enable-zip

–enable-gd-native-ttf

–enable-pdo

–enable-fpm

–enable-freetype

4.编译遇到问题:error: xml2-config not found.解决办法:

  (1)去官网
下载源码。我用的版本是libxml2-2.9.0.tar.gz,
解压到/usr/src,执行命令:sudo tar -zxvf libxml2-2.9.0.tar.gz  -C
/usr/src

  (2)进入目录/usr/src/libxml2-2.9.0,在root下执行或者用sudo命令执行:
sudo ./configure –prefix=/usr/local/libxml2/ ; make; make install

    (3) 进入php目录中编译时加上–with-libxml-dir=/usr/local/libxml2

5.再次编译,遇到问题:checking if the location of ZLIB install directory
is defined… no ; configure: error: Cannot find libz. 解决办法:

  (1)去网址
下载zlib源码。我下的是版本zlib-1.2.7.tar.gz,解压到/usr/src,执行命令:sudo
tar -zxvf zlib-1.2.7.tar.gz  -C /usr/src

  (2)进入目录/usr/src/zlib-1.2.7/,执行命令:sudo ./configure
–prefix=/usr/local/zlib;make;make install

  (3)进入php目录中重新编译,增加新参数 –with-zlib-dir=/usr/local/zlib

6.再次编译,遇到问题:error: Please reinstall the BZip2 distribution.
解决办法:

  (1)去网站
下载源码。我用的版本是bzip2-1.0.6.tar.gz,执行命令:sudo tar -zxvf
bzip2-1.0.6.tar.gz -C /usr/src

  (2)进入目录/usr/src/bzip2-1.0.6/,sudo方式执行:make;make
install(下的源码中并没有configure)

  (3)重新编译,不用增加新参数

7.再次编译,遇到问题:

checking if we should use cURL for url streams… no checking for cURL
in default path… not found

configure: error: Please reinstall the libcurl distribution – easy.h
should be in <curl-dir>/include/curl/

解决办法是重装libcurl

  (1)去网站
下载libcurl源码。我用的版本是curl-7.28.0.tar.gz,执行命令:sudo tar
-zxvf curl-7.28.0.tar.gz -C /usr/src

  (2)进入/usr/src/curl-7.28.0目录,用sudo执行命令:./configure
–prefix=/usr/local/curl;make;make install

  (3)重新编译php,增加参数–with-curl=/usr/local/curl

8.再次编译,遇到问题:configure: error: jpeglib.h not found. 解决办法:

  (1)去网站
下载源码。我用的版本是jpegsrc.v8d.tar.gz,执行命令:sudo tar -zxvf
jpegsrc.v8d.tar.gz -C /usr/src

  (2)进入/usr/src/jpegsrc.v8d目录,sudo方式执行命令:sudo ./configure
–prefix=/usr/local/jpeg;make;make install;

  (3)重新编译php,增加参数–with-jpeg-dir=/usr/local/jpeg

9.再次编译,遇到问题:configure: error: png.h not found.

  (1)去网站
下载源码,我用的版本是libpng-1.5.13.tar.gz,执行命令:sudo tar
-zxvflibpng-1.5.13.tar.gz -C /usr/src

  (2)进入/usr/src/libpng-1.5.13目录,sudo方式执行命令:sudo
./configure –prefix=/usr/local/png;make;make install;

  (3)这时出现了configure: error: zlib not
installed的错误,明明之前已经装过的,但是这里还是报错。在网上查了解决办法如下:

         
3.1)进入zlib的源文件目录(这里我的是/usr/src/zlib-1.2.7/),执行命令
make clean,清除zlib;

    3.2)重新配置 ./configure,后面不要接–prefix参数;

    3.3)make && make install;

    3.4)进入libpng目录(我的是/usr/src/libpng-1.5.13/),执行命令
./configure –prefix=/usr/local/png;

    3.5)make && make install;

  (4)重新编译php,这时增加参数–with-png-dir=/usr/local/png。

10.再次编译,遇到问题:configure: error: mcrypt.h not found. Please
reinstall libmcrypt.

  (1)去网站
的下载源码,我下的版本是libmcrypt-2.5.7.tar.gz;执行命令:sudo tar -zxvf
libmcrypt-2.5.7.tar.gz -C /usr/src

  (2)进入/usr/src/libmcrypt-2.5.7目录,sudo方式执行命令:./configure
prefix=/usr/local/libmcrypt/;make ;make install

  (3)重新编译php,这时增加参数–with-mcrypt=/usr/local/libmcrypt

11.再次编译,就没有遇到问题了,虽然显示了configure: WARNING:
unrecognized options: –enable-freetype,但结果依然是Thank you for using
PHP. 此时的编译php的参数如下:

  (1)sudo ./configure –prefix=/usr/local/php –enable-fpm 
–with-zlib –enable-mbstring –with-openssl –with-mysql –with-mysqli
–with-mysql-sock –with-gd –enable-gd-native-ttf  –enable-pdo
–with-pdo-mysql –with-gettext –with-curl –with-pdo-mysql
–enable-sockets –enable-bcmath –enable-xml –with-bz2 –enable-zip
–enable-freetype –with-libxml-dir=/usr/local/libxml2
–with-zlib-dir=/usr/local/zlib –with-curl=/usr/local/curl
–with-jpeg-dir=/usr/local/jpeg –with-png-dir=/usr/local/png
–with-mcrypt=/usr/local/libmcrypt
–with-apxs2=/usr/local/apache2/bin/apxs

(备注:一定要加这个 apxs – APache eXtenSion tool
用来制作apache的扩展模块DSO,要使用这个工具,安装apache的时候就必须添加enable-so以支持DSO.
如果没有这个的话apache是只会解析静态页面的,第一次编译时没加,怎么配置都不行,第二次加了该选项重新编译以后就都OK了。)

 (2)sudo make

 (3)sudo make install

12.为了在命令行可以直接使用php命令,编辑 sudo vim
/etc/environment,将php的bin目录路径添加进去,我的是/usr/local/php/bin,然后reboot机器

13.为了使Apache支持PHP,解决办法:

  (1)进入apache配置目录,执行命令:cd /usr/local/apache2/conf。
编辑文件:sudo vim httpd.conf

  (2)查找字符串AddType,并增加

        AddType application/x-httpd-php .php .php3 .htm .phtml .php4

        AddType application/x-httpd-php-source .phps
添加LoadModule php5_module modules/libphp5.so #如果存在就不必要了

        然后重启apache使配置生效

  (3)查找字符串DirectoryIndex,并修改为 DirectoryIndex index.html
index.php3 index.php default.php

  1. 修改php配置.

 
(1)进入php源码目录,选择php.ini-development复制一份到/usr/local/lib,并改名为php.ini使用vim打开,查找extension_dir,修改为extension_dir
= “D:/php/php5/ext”,读     
者根据自己的目录结构配置,目的是找到和php.ini同目录下的ext文件夹中的扩展库。

 (2)查找extension=php_,去掉extension=php_curl.dll,extension=php_gd2.dll,extension=php_mbstring.dll,extension=php_mysql.dll,extension=php_mysqli.dll,extension=php_pdo_mysql.dll,extension=php_xmlrpc.dll前面
的分号。查找short_open_tag = Off把它修改成short_open_tag =
On,让其支持短标签(我看注释这个默认是打开的)。

Php.ini配置完成

配置apache的config

 15.查找字符串DocumentRoot,可以设置Apache虚拟根目录

 16.查找字符串ServerAdmin,并修改成自己的邮箱

 17.在apache根文件中增加一个test.php文件,<?php phpinfo();
?>,然后访问127.0.0.1/test.php,查看结果。

自己用的编译版本

./configure

–profix=/user/local/php

–with-apxs2=/usr/local/apache/bin/apxs

–with-config-file-path=/usr/local/PHP/etc

–with-mysql=/usr/local/mysql

–with-mysqli=/usr/local/mysql/bin/mysql_config

–with-libxml-dir= #libxml目录

–with-zlib-dir= #zlib目录

–enable-sysvsem

–enable-sockets

–enable-pcntl

–enable-mbstring

–enable-mysqlnd

–enable-opcache

–enable-shmop

–enable-zip

–enable-ftp

–enable-gd-native-ttf

–enable-wddx

–enable-soap

–enable-fpm

 

 

 

附录:网上找的php各个版本的编译参数如下。

Fast-CGI:

./configure –prefix=/usr/local/php –enable-fastcgi
–enable-force-cgi-redirect –with-config-file-path=/etc –with-zlib
–with-mysql –with-xml –with-gd –enable-gd-native-ttf
–enable-gd-jis-conv –with-freetype-dir –with-jpeg-dir –with-png-dir
–enable-mbstring

PHP4-Server:

./configure –prefix=/usr/local/php
–with-apxs2=/usr/local/apache2/bin/apxs –with-mysql
–with-config-file-path=/etc –with-gd –enable-gd-native-ttf
–enable-gd-jis-conv –with-freetype-dir –with-jpeg-dir –with-png-dir
–with-zlib –enable-xml –enable-mbstring

PHP4-Max:

./configure –prefix=/usr/local/php
–with-apxs2=/usr/local/apache/bin/apxs –mandir=/usr/share/man
–with-mysql=/usr/local/mysql –with-config-file-path=/usr/local/php/etc
–with-openssl=/usr/local/openssl-0.9.7e –with-gd
–enable-gd-native-ttf –enable-gd-jis-conv –with-freetype-dir
–with-jpeg-dir –with-png-dir –with-zlib –with-bz2 –with-inifile
–with-hyperwave –enable-xml –enable-track-vars –enable-dba
–enable-dbase –enable-filepro –enable-ftp –enable-versioning
–enable-memory-limit –enable-calendar –enable-session
–enable-sockets –enable-sysmsg –enable-sysvsem –enable-sysvshm
–enable-tokenizer –enable-overload –enable-ctype –enable-sigchild
–enable-magic-quotes –enable-roxen-zts –enable-fastcgi –enable-dbx
–enable-dio –enable-shmop –enable-mbstring

PHP5-Server:

./configure –prefix=/usr/local/php
–with-apxs2=/usr/local/apache2/bin/apxs –with-zlib-dir –with-bz2
–with-tiff-dir –with-libxml-dir –with-gd –with-freetype-dir
–with-jpeg-dir –with-png-dir –with-ttf –enable-mbstring
–with-mysql=/usr/lib/mysql –with-config-file-path=/etc –disable-ipv6
–enable-gd-native-ttf

PHP5-Standard:

./configure –prefix=/usr/local/php
–with-apxs2=/usr/local/apache/bin/apxs –mandir=/usr/share/man
–with-openssl=/usr/local/openssl-0.9.7e –with-zlib –with-bz2
–with-tiff-dir –with-libxml-dir –enable-dio –enable-ftp –with-gd
–with-freetype-dir –with-jpeg-dir –with-png-dir –with-zlib-dir
–with-bz2-dir –with-ttf –enable-mbstring
–with-mysql=/usr/local/mysql –with-config-file-path=/usr/local/php/etc
–disable-ipv6 –enable-gd-native-ttf

PHP5-Max:

./configure –prefix=/usr/local/php
–with-apxs2=/usr/local/apache/bin/apxs –mandir=/usr/share/man
–with-openssl=/usr/local/openssl-0.9.7e –with-zlib –with-bz2
–with-tiff-dir –with-libxml-dir –enable-dio –enable-ftp –with-gd
–with-freetype-dir –with-jpeg-dir –with-png-dir –with-zlib-dir
–with-bz2-dir –with-ttf –with-inifile –enable-dba –enable-dbase
–enable-filepro –enable-versioning –enable-memory-limit
–enable-calendar –enable-sockets –enable-sysvsem –enable-sigchild
–enable-magic-quotes –enable-roxen-zts –enable-fastcgi –enable-dbx
–enable-shmop –enable-mbstring –with-mysql=/usr/local/mysql
–with-config-file-path=/usr/local/php/etc –disable-ipv6
–enable-gd-native-ttf

深入理解PHP中的ini配置

剖析PHP脚本的超时机制

Ubuntu 14.04下搭建PHP开发环境PDF 

PHP 7革新与性能优化

PHP 7 ,你值得拥有   

在 CentOS 7.x / Fedora 21 上面体验 PHP 7.0   

CentOS 6.3 安装LNMP (PHP 5.4,MyySQL5.6)  

在部署LNMP的时候遇到Nginx启动失败的2个问题  

Ubuntu安装Nginx php5-fpm MySQL(LNMP环境搭建)  

《细说PHP》高清扫描PDF+光盘源码+全套教学视频  

CentOS 6中配置PHP的LNMP的开发环境   

PHP 的详细介绍:请点这里
PHP 的下载地址:请点这里

下编译安装PHP 1. 去php官网下载源码

,我下载使用的版本是(php-5.4.8.tar.gz) 2. 安装环境 yum install xml2 2.
解压…

交叉编译nginx

软件版本:nginx-1.6.2

依赖源码:pcre,zlib(这里是需要用到它们的源码)

交叉编译器:arm-hisiv200-linux-gnueabi

linux版本:32位ubuntu(这个很重要,主要是使用32位x86系统才能进行编译成功,因为字长不一样)

交叉编译nginx与交叉编译php5不同就是nginx用的是依赖的库的源码,而php5用的是库文件。

  1. 进入nginx-1.6.2源码目录。
  2. 在配置和编译nginx会出现很多错误,我们一个一个解决,首先我使用的configure配置如下:

    #!/bin/bash
    
    CC_PATH=/home/shanlink/Cross_compile/arm-hisiv200-linux/bin/arm-hisiv200-linux-gnueabi-gcc
    CPP_PATH=/home/shanlink/Cross_compile/arm-hisiv200-linux/bin/arm-hisiv200-linux-gnueabi-g++
    INSTALL_PATH=/home/shanlink/Cross_compile/nginx_ccs/
    PCRE_PATH=/home/shanlink/Cross_compile/pcre-8.11/
    ZLIB_PATH=/home/shanlink/Cross_compile/zlib-1.2.3/
    CC_OPTS="-I /home/shanlink/Cross_compile/arm-hisiv200-linux/target/include/"
    
    ./configure --prefix=$INSTALL_PATH --with-zlib=$ZLIB_PATH --with-pcre=$PCRE_PATH --with-cc=$CC_PATH --with-cpp=$CPP_PATH --with-cc-opt=$CC_POTS --with-ld-opt="-L /home/shanlink/Cross_compile/arm-hisiv200-linux/target/lib/"
    
  3. 好的,把以上内容做成一个运行脚本,运行,出现一个错误:

    checking for OS
     + Linux 3.13.0-43-generic x86_64
    checking for C compiler ... found but is not working
    
    ./configure: error: C compiler /home/shanlink/Cross_compile/arm-hisiv200-linux/bin/arm-hisiv200-linux-gnueabi-gcc is not found
    

    解决办法就是:编辑auto/cc/name文件,在文件开头有如下一段,注释掉exit
    1

    if [ "$NGX_PLATFORM" != win32 ]; then
    
        ngx_feature="C compiler"
        ngx_feature_name=
        ngx_feature_run=yes
        ngx_feature_incs=
        ngx_feature_path=
        ngx_feature_libs=
        ngx_feature_test=
        . auto/feature
    
        if [ $ngx_found = no ]; then
            echo
            echo $0: error: C compiler $CC is not found
            echo
            #exit 1        注释掉这一行     
        fi
    
    fi
    
  4. 再次运行我们的配置脚本,这时候出现

    checking for TCP_INFO ... found
    checking for accept4() ... found
    checking for int size ...objs/autotest: 1: objs/autotest: Syntax error: word unexpected (expecting ")")
      bytes
    
    ./configure: error: can not detect int size
    cat: objs/autotest.c: No such file or directory
    

    解决方法:编辑auto/types/sizeof文件,找到

    ngx_test="$CC $CC_TEST_FLAGS $CC_AUX_FLAGS 
              -o $NGX_AUTOTEST $NGX_AUTOTEST.c $NGX_LD_OPT $ngx_feature_libs"
    
    将的$CC改为x86上使用的gcc
    
    ngx_test="gcc $CC_TEST_FLAGS $CC_AUX_FLAGS 
              -o $NGX_AUTOTEST $NGX_AUTOTEST.c $NGX_LD_OPT $ngx_feature_libs"
    
  5. 再次运行我们的配置脚本,这时应该可以顺利配置完成。

  6. 执行make,这时候会出现一个错误

    checking for C compiler default output file name... a.out
    checking for suffix of executables... 
    checking whether we are cross compiling... configure: error: in `/home/shanlink/Cross_compile/pcre-8.11':
    configure: error: cannot run C compiled programs.
    If you meant to cross compile, use `--host'.
    See `config.log' for more details.
    make[1]: *** [/home/shanlink/Cross_compile/pcre-8.11//Makefile] Error 1
    make[1]: Leaving directory `/home/shanlink/Cross_compile/nginx-1.6.2'
    make: *** [build] Error 2
    

    这个是由于nginx在编译时会同时配置pcre并且进行编译,而由于是交叉编译,pcre的配置时需要添加–host=arm-hisiv200-linux-gnueabi,因为是由nginx自动配置的,所以我们需要手动添加此选项于pcre,然后再make,此选项添加在

    文件:objs/Makefile
    
    找到如下一段:
    /home/shanlink/Cross_compile/pcre-8.11//Makefile:    objs/Makefile
        cd /home/shanlink/Cross_compile/pcre-8.11/ 
        && if [ -f Makefile ]; then $(MAKE) distclean; fi 
        && CC="$(CC)" CFLAGS="-O2 -fomit-frame-pointer -pipe " 
        ./configure --disable-shared 
    
    将
        ./configure --disable-shared 
    改为
        ./configure --disable-shared --host=arm-hisiv200-linux-gnueabi(这个交叉编译器前缀填你们电脑上自己的)
    
  7. 如果遇到一下错误,原因是你们的linux系统是64位的,而arm上一般都是32位的,所以会有这个错误,解决办法就是重新装一个32位的linux系统。

    src/core/ngx_slab.c: In function 'ngx_slab_alloc_locked':
    src/core/ngx_slab.c:209: error: integer constant is too large for 'long' type
    src/core/ngx_slab.c:209: error: comparison is always true due to limited range of data type
    src/core/ngx_slab.c:221: error: integer constant is too large for 'long' type
    src/core/ngx_slab.c:221: error: comparison is always false due to limited range of data type
    src/core/ngx_slab.c:223: error: integer constant is too large for 'long' type
    src/core/ngx_slab.c:223: error: comparison is always true due to limited range of data type
    src/core/ngx_slab.c:253: error: integer constant is too large for 'long' type
    src/core/ngx_slab.c:253: error: comparison is always true due to limited range of data type
    src/core/ngx_slab.c:262: error: integer constant is too large for 'long' type
    src/core/ngx_slab.c:262: error: comparison is always false due to limited range of data type
    src/core/ngx_slab.c:289: error: left shift count >= width of type
    src/core/ngx_slab.c:292: error: integer constant is too large for 'long' type
    src/core/ngx_slab.c:294: error: left shift count >= width of type
    src/core/ngx_slab.c:304: error: integer constant is too large for 'long' type
    src/core/ngx_slab.c:376: error: left shift count >= width of type
    src/core/ngx_slab.c: In function 'ngx_slab_free_locked':
    src/core/ngx_slab.c:499: error: integer constant is too large for 'long' type
    src/core/ngx_slab.c:499: error: comparison is always false due to limited range of data type
    src/core/ngx_slab.c:552: error: integer constant is too large for 'long' type
    src/core/ngx_slab.c:575: error: integer constant is too large for 'long' type
    src/core/ngx_slab.c:575: error: comparison is always false due to limited range of data type
    src/core/ngx_slab.c:582: error: integer constant is too large for 'long' type
    src/core/ngx_slab.c: In function 'ngx_slab_alloc_pages':
    src/core/ngx_slab.c:643: error: integer constant is too large for 'long' type
    src/core/ngx_slab.c:652: error: integer constant is too large for 'long' type
    src/core/ngx_slab.c:652: error: large integer implicitly truncated to unsigned type
    make[1]: *** [objs/src/core/ngx_slab.o] Error 1
    make[1]: Leaving directory `/home/shanlink/Cross_compile/nginx-1.6.2'
    make: *** [build] Error 2
    
  8. 这时候继续make,还会出现两个错误,一个是

    src/os/unix/ngx_errno.c: In function 'ngx_strerror':
    src/os/unix/ngx_errno.c:37: error: 'NGX_SYS_NERR' undeclared (first use in this function)
    src/os/unix/ngx_errno.c:37: error: (Each undeclared identifier is reported only once
    src/os/unix/ngx_errno.c:37: error: for each function it appears in.)
    src/os/unix/ngx_errno.c: In function 'ngx_strerror_init':
    src/os/unix/ngx_errno.c:58: error: 'NGX_SYS_NERR' undeclared (first use in this function)
    make[1]: *** [objs/src/os/unix/ngx_errno.o] Error 1
    make[1]: Leaving directory `/home/shanlink/Cross_compile/nginx-1.6.2'
    make: *** [build] Error 2
    

    解决方法就是打开objs/ngx_auto_config.h,添加

    #ifndef NGX_SYS_NERR
    #define NGX_SYS_NERR    132
    #endif
    

    另一个错误

    objs/src/event/ngx_event_accept.o: In function `ngx_event_accept':
    /home/shanlink/Cross_compile/nginx-1.6.2/src/event/ngx_event_accept.c:64: warning: warning: accept4 is not implemented and will always fail
    objs/src/core/ngx_cycle.o: In function `ngx_init_cycle':
    /home/shanlink/Cross_compile/nginx-1.6.2/src/core/ngx_cycle.c:457: undefined reference to `ngx_shm_free'
    /home/shanlink/Cross_compile/nginx-1.6.2/src/core/ngx_cycle.c:462: undefined reference to `ngx_shm_alloc'
    /home/shanlink/Cross_compile/nginx-1.6.2/src/core/ngx_cycle.c:648: undefined reference to `ngx_shm_free'
    objs/src/event/ngx_event.o: In function `ngx_event_module_init':
    /home/shanlink/Cross_compile/nginx-1.6.2/src/event/ngx_event.c:525: undefined reference to `ngx_shm_alloc'
    collect2: ld returned 1 exit status
    make[1]: *** [objs/nginx] Error 1
    make[1]: Leaving directory `/home/shanlink/Cross_compile/nginx-1.6.2'
    make: *** [build] Error 2
    shanlink@ubuntu:~/Cross_compile
    

    同样的,我们需要修改objs/ngx_auto_config.h文件,在文件中加入

    #ifndef NGX_HAVE_SYSVSHM
    #define NGX_HAVE_SYSVSHM 1
    #endif
    
  9. 好了,这时候make && make install就应该能编译过去了。

  10. 如果遇到其他编译问题,请参考:

  1.下载地址:  ,选择下载相应版本,并解压到目录下

交叉编译squid

软件版本:squid-2.7-STABLE9

交叉编译器:arm-hisiv200-linux-gnueabi

系统:32位ubuntu

在对squid进行交叉编译时,需要用到x86版本的squid,所以我们要进行两个版本的编译。

  1. 首先编译x86版本的使用配置为

    ./configure --prefix=X86_SQUID_PATH
    
  2. make && make install

  3. 进入到squid源码目录下的src/文件夹,有个cf_gen程序,备份起来,交叉编译时会用到。
  4. 建立一个arm-linux.cache文件,写入

    ac_cv_epoll_works=
    ac_cv_af_unix_large_dgram=
    ac_cv_func_setresuid=
    ac_cv_func_va_copy=
    ac_cv_func___va_copy=
    
  5. 执行

    #!/bin/bash
    
    ./configure --host=arm-hisiv200-linux-gnueabi --prefix=/home/shanlink/Cross_compile/squid_ccs/ --cache-file=arm-linux.cache
    

    这时应该是能够顺利通过的

  6. 执行make,会出现一个错误

    ./cf_gen: cannot execute binary file
    
  7. 将之前备份的x86的cf_gen复制到src/目录下替换arm的

  8. 再次执行make,应该可以顺利通过编译
  9. make install
  10. 完成

  2.安装依赖包 yum -y install pcre*  yum -y install openssl*

  
  如果安装出现在下面的错误是缺少编译环境。安装编译源码所需的工具和库 
       ./configure: error: C compiler cc is not found 
      #yum install gcc gcc-c++ ncurses-devel perl

  3. a、执行 ./configure –prefix=/usr/local/nginx
–with-http_ssl_module –with-http_stub_status_module –with-pcre

    b、编译 make

    c、安装 make install (如果是非root用户 make 和sudo make install
分开 同理,其他的安装包也是这样)

  4. 建立软链接:# ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/

  5. 配置nginx.conf 支持php

    进入/usr/local/nginx/conf目录,编辑nginx.conf

    

location / {
            root   /home/www;    #根目录,可指定目录
            index index.php index.html index.htm; #增加index.php 默认支持php
        }

#打开支持php
location ~ .php$ {
           # root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            #将/scripts 改为 root 指定目录地址
            #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            fastcgi_param  SCRIPT_FILENAME  /home/www$fastcgi_script_name;
            include        fastcgi_params;
        }

……
#在配置未见末尾加入  include vhost/*.conf;  建立虚拟主机配置目录

    建立虚拟主机配置目录,并将此目录导入到nginx.conf中

    # mkdir vhost

    # vim ./nginx.conf (在最后大括号前添加一行并保存退出: include
vhost/*.conf; )

  6. 可在vhost目录内新建虚拟主机配置文件,以.conf结尾。

server {
    listen 80;#监听80端口,接收http请求
    server_name www.lblog.com;#域名
    root /home/www/blog;#准备存放代码工程的路径
    index index.php index.html index.htm;

    location / {
       try_files $uri $uri/ /index.php$is_args$args; #去除 index.php
    }

    location ~ .php$ {
        #fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        #fastcgi_split_path_info ^(.+.php)(/.+)$;
        #fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        #include fastcgi_params;
        try_files $uri =404;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index index.php;
        include fastcgi.conf;#加载nginx的fastcgi模块
    }

}

  

 (2)安装php(源码编译安装)

  1.下载地址:

  2.安装依赖包 :yum -y install libxml2 libxml2-devel openssl
openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel
libmcrypt-devel

  3. 由于centOS没有libmcrypt,所以要先下载第三方源

wget http://www.atomicorp.com/installers/atomic
sh ./atomic
yum install php-mcrypt libmcrypt-devel

  4. 解压安装包并cd到安装包目录下,并做安装配置

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysqli --with-iconv --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-zlib --enable-pdo --with-pdo-mysql --enable-opcache

       5.make && make install

  6. cd  /usr/local/php
进行相关配置  

cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
cp php.ini-production /usr/local/php/etc/php.ini

     修改www.conf 下面的user = www ,group=www (需要先创建)

     接着运行/usr/local/php/sbin/php-fpm 就可以启动php了

发表评论

电子邮件地址不会被公开。 必填项已用*标注