nginx + php 安装与整合

环境:

Linux moban 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

1、我们这里使用的php是5.3.27版本,在企业中一般是5.2.17这个比较经典的版本。
2、安装之前我们要确认mysql和nginx已经安装,运行时没有问题的,最好检查一遍。

3、检查相关的包是否安装:
    rpm -qa zlib libxml libjpeg freetype libpng gd  curl libiconv  zlib-devel libxml2-devel     libjpeg-devel freetype-devel libpng-devel gd-devel curl-devel
    不装不影响安装,但是将来网站使用的时候会出现问题
    yum install zlib libxml libjpeg freetype libpng gd  curl libiconv  zlib-devel         libxml2-devel libjpeg-devel freetype-devel libpng-devel gd-devel curl-devel -y

4、安装字符集转换库相关,是一个命令; 注:必须存在devel
    tar zxf libiconv-1.14.tar.gz
    cd libiconv-1.14
    ./configure --prefix=/usr/local/libiconv
    make
    make install
    cd ../

5、添加一个加密相关的库
    wget "http://downloads.sourceforge.net/mcrypt/libmcrypt-    2.5.8.tar.gz?modtime=1171868460&big_mirror=0"
    tar zxf libmcrypt-2.5.8.tar.gz
    cd libmcrypt-2.5.8
    ./configure
    make
    make install
    sleep 2
    /sbin/ldconfig
    cd libltdl/
    ./configure --enable-ltdl-install
    make
    make install
    cd ../../

6、安装mhash加密扩展库

    wget "http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz?modtime=1175740843&big_mirror=0"
    tar zxf mhash-0.9.9.9.tar.gz
    cd mhash-0.9.9.9/
    ./configure
    make
    make install
    sleep 2
    cd ../

    rm -f /usr/lib64/libmcrypt.*
    rm -f /usr/lib64/libmhash*
    ln -s /usr/local/lib64/libmcrypt.la /usr/lib64/libmcrypt.la
    ln -s /usr/local/lib64/libmcrypt.so /usr/lib64/libmcrypt.so
    ln -s /usr/local/lib64/libmcrypt.so.4 /usr/lib64/libmcrypt.so.4
    ln -s /usr/local/lib64/libmcrypt.so.4.4.8 /usr/lib64/libmcrypt.so.4.4.8
    ln -s /usr/local/lib64/libmhash.a /usr/lib64/libmhash.a
    ln -s /usr/local/lib64/libmhash.la /usr/lib64/libmhash.la
    ln -s /usr/local/lib64/libmhash.so /usr/lib64/libmhash.so
    ln -s /usr/local/lib64/libmhash.so.2 /usr/lib64/libmhash.so.2
    ln -s /usr/local/lib64/libmhash.so.2.0.1 /usr/lib64/libmhash.so.2.0.1
    ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config

7、另一个加密库
    wget "http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz?modtime=1194463373&   big_mirror=0"
    tar zxf mcrypt-2.6.8.tar.gz
    cd mcrypt-2.6.8/
    /sbin/ldconfig
    ./configure LD_LIBRARY_PATH=/usr/local/lib
    make
    make install
    cd ../
    sleep 2

8、yum install libxslt* -y

----------------------------------------上述准备完成后-------------------------------


9、解压php : tar xf php-5.3.27.tar.gz
            pwd
            /root/php-5.3.27
   配合nginx编译:./configure \
                --prefix=/application/php5.3.27 \
                --with-mysql=/application/mysql \
                --with-iconv-dir=/usr/local/libiconv \
                --with-freetype-dir \
                --with-jpeg-dir \
                --with-png-dir \
                --with-zlib \
                --with-libxml-dir=/usr \
                --enable-xml \
                --disable-rpath \
                --enable-safe-mode \
                --enable-bcmath \
                --enable-shmop \
                --enable-sysvsem \
                --enable-inline-optimization \
                --with-curl \
                --with-curlwrappers \
                --enable-mbregex \
                --enable-fpm \
                --enable-mbstring \
                --with-mcrypt \
                --with-gd \
                --enable-gd-native-ttf \
                --with-openssl \
                --with-mhash \
                --enable-pcntl \
                --enable-sockets \
                --with-xmlrpc \
                --enable-zip \
                --enable-soap \
                --enable-short-tags \
                --enable-zend-multibyte \
                --enable-static \
                --with-xsl \
                --with-fpm-user=nginx \
                --with-fpm-group=nginx \
                --enable-ftp

    关注:Thank you for using PHP.表示没有问题。

    继续:make && make install

    报错: libmysqlclient.so.18: cannot open shared object file: No such file or directory
           make: *** [ext/phar/phar.php] Error 127   

    解决:  find / -name "libmysqlclient.so.18"
            /home/oldboy/tools/mysql-5.5.32-linux2.6-x86_64/lib/libmysqlclient.so.18
            /application/mysql-5.5.32-linux2.6-x86_64/lib/libmysqlclient.so.18

            把路径/home/oldboy/tools/mysql-5.5.32-linux2.6-x86_64/lib/ 、/application/mysql-5.5.32-linux2.6-x86_64/lib/追加到/etc/ld.so.conf里用ldconfig生效。

     报错:Generating phar.phar
            chmod: 无法访问"ext/phar/phar.phar":

     解决:mkdir ext/phar/phar.phar -p

     如:echo $?返回为0 即编译成功。

10、创建软链接:ln -s /application/php5.3.27/ /application/php

11、拷贝配置文件:cp php.ini-production  /application/php/lib/php.ini

12、启动文件重命名:mv /application/php/etc/php-fpm.conf.defult  php-fpm.conf

13、启动php:/application/php/sbin/php-fpm
             (-t 检查语法)

14、查看php的9000端口是否成功: netstat -lntup|grep php-fpm

           

-----------------------------------整合nginx------------------------------------

编辑nginx的配置文件:

      

    vi ../nginx-1.6.2/conf/extra/blog.conf

    server {
        listen       8000;
        server_name  blog.etiantian.org;
            root   html/blog;
            index  index.php index.html index.htm;
            access_log  logs/blog_access.log;
    location ~ .*\.(php|php5)?$
    {
     fastcgi_pass  127.0.0.1:9000;
     fastcgi_index index.php;
     include fastcgi.conf;

    }
    }

    vi nginx.conf

      server {
            listen       80;
            server_name  blog.etiantian.org;
            root   html/blog;
            index  index.php index.html index.htm;
            access_log  logs/blog_access.log;
        location ~ .*\.(php|php5)?$
        {
         fastcgi_pass  127.0.0.1:9000;
         fastcgi_index index.php;
         include fastcgi.conf;
        }
        }

    创建index.php文件。

     <?php
    phpinfo ();
    ?>

检查语法重启nginx服务。

访问即可。~               

本文出自 “一如既往” 博客,谢绝转载!

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。