nginx+php(5.4.14)安装、配置详解(单机版)

环境:

系统: centos 6.2 linux2.6

php: 5.4.14 (当前最新版本)

nginx :1.3.16(当前最新版本)


1.php的安装

安装前.先安装些软件和库文件
yum install -y gcc gcc-c++  make zlib zlib-devel pcre pcre-devel  libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers

部分不是必须的哦,必须的有:libpng,jpeg,freetype,gd

1.1遇到的问题

如果我们不用上面的命令一次安装,则会遇到下面的问题:

error 1
checking for xml2-config path... 
configure: error: xml2-config not found. Please check your libxml2 installation.

(看提示就明白 是一个lib库没装  先用 yum search 名字 看是否能搜到名字 ,找到名字后 把软件包 开发包装上)
解决办法
yum install libxml2-devel.x86_64


error 2
checking for pkg-config... /usr/bin/pkg-config
configure: error: Cannot find OpenSSL's <evp.h>
这是ssl没装
解决办法
 yum  install  openssl.x86_64 openssl-devel.x86_64 -y

error 3
checking for BZip2 in default path... not found
configure: error: Please reinstall the BZip2 distribution
这是bzip2软件包没有安装
解决办法
yum install bzip2-devel.x86_64 -y

error 4
configure: error: Please reinstall the libcurl distribution -
    easy.h should be in <curl-dir>/include/curl/
curl和curl库文件没有安装

解决办法
yum install libcurl.x86_64 libcurl-devel.x86_64 -y

error 5
checking whether to enable JIS-mapped Japanese font support in GD... no
checking for fabsf... yes
checking for floorf... yes
configure: error: jpeglib.h not found

GD库没有安装
解决办法
yum install libjpeg.x86_64 libpng.x86_64 freetype.x86_64 libjpeg-devel.x86_64 libpng-devel.x86_64 freetype-devel.x86_64 -y


error 6
checking for stdarg.h... (cached) yes
checking for mcrypt support... yes
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
libmcrypt库没有安装 ,要是不能用yun安装的话  就要去下载个gz包 自己编译安装
给个地址:http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/
(编译安装  ./configure --piefix=/usr/local/libmcrypt   make && make install)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
要是错误里面含有mysql的  那是mysql-devel 没有安装

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

1.2编译、安装

这里安最少的编译,目的是能跑得出来,如果图精简,则执行下面命令就OK

$ yum install -y gcc-c++ gcc make libxml2-devel libjpeg-devel libpng-devel

/configure  --enable-fastcgi --enable-fpm
注:Nginx+PHP整合,在安装时必须启用--enable-fastcgi和 --enable-fpm,这两个选项是做什么的上面已经描述。执行完后系统会提示--enable-fastcgi是一个未知选项,我们不必理会

$ make && make install

出现
Generating files configure: creating ./config.status creating main/internal_functions.c creating main/internal_functions_cli.c
+--------------------------------------------------------------------+
| License:                                                           |

| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE.  By continuing this installation |
| process, you are bound by the terms of this license agreement.     |

| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |


+--------------------------------------------------------------------+
Thank you for using PHP.
onfig.status: creating php5.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/fpm/php-fpm.conf
config.status: creating sapi/fpm/init.d.php-fpm
config.status: creating sapi/fpm/php-fpm.8
config.status: creating sapi/fpm/status.html
config.status: creating main/php_config.h
config.status: executing default commands


表示PHP安装工作成功

2.安装nginx

可以到官网上载最近的版本,http://nginx.org/

解压后,直接 让其默认安装

$ ./configure  && make && make install


3.修改配置文件

make完成之后  到php的解压目录 找出php.ini-production 复制到 /usr/local/etc/ 下 文件名改成php.ini

$ cp php.ini-production /usr/local/etc/php.ini 

将/usr/local/etc/php-fpm.conf.default 复制一份,并改名了php-fpm.conf.default

$ cp /usr/local/etc/php-fpm.conf.default  /usr/local/etc/php-fpm.conf


3.1.修改 /usr/local/nginx/conf/nginx.conf

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}


        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000; //监听本地的php-fpm的9000端口
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html/$fastcgi_script_name;  #下画线的是php文件所放的路径
            include        fastcgi_params;
        }



        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one


3.2.修改 /usr/local/etc/php-fpm.conf 文件

*********************************************************

  1. [global]
  2. ; Pid file
  3. ; Note: the default prefix is /usr/local/webserver/php/var
  4. ; Default Value: none
  5. pid = run/php-fpm.pid

  6. ; Error log file
  7. ; If it's set to "syslog", log is sent to syslogd instead of being written
  8. ; in a local file.

***********************************************************************************************************

;                            specific port;
;   '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = 127.0.0.1:9000 #这里不用改,但是强调一下,nginx做代理的时候需要使用


; Set listen(2) backlog.
; Default Value: 128 (-1 on FreeBSD and OpenBSD)

*************************************************************************************************************************


上面红色部分是修改的部分,其它保持不变


4.运行测试 

运行php-fpm 和nginx

$ /usr/local/sbin/php-fpm

$ /usr/local/nginx/sbin/nginx


在niginx 的安装目录下找到html目录(默认网站目录),新建一个index.php

内容为:

<?php
echo phpinfo();
?>

最后在另外一台机器上访问这个网页,即可看到php的页面信息了

此时大功告成


配置参考:

安装Nginx 1.2.0+PHP 5.4.3(FastCGI)+MySQL 5.5.24  http://blog.chinaunix.net/uid-20556054-id-3226209.html

编译安装PHP 时遇到问题解决方法.  http://www.cnblogs.com/z-ping/archive/2012/06/18/2553929.html

CentOS+Nginx+PHP+MySQL详细配置  http://www.jb51.net/article/26597.htm

 Nginx 0.8.x + PHP 5.2.13(FastCGI)搭建胜过Apache十倍的Web服务器  http://blog.s135.com/nginx_php_v6/



你可能感兴趣的:(nginx+php(5.4.14)安装、配置详解(单机版))