环境:
系统: centos 6.2 linux2.6
php: 5.4.14 (当前最新版本)
nginx :1.3.16(当前最新版本)
安装前.先安装些软件和库文件
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
如果我们不用上面的命令一次安装,则会遇到下面的问题:
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
这是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和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 没有安装
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
这里安最少的编译,目的是能跑得出来,如果图精简,则执行下面命令就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安装工作成功
可以到官网上载最近的版本,http://nginx.org/
解压后,直接 让其默认安装
$ ./configure && make && make install
$ 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 文件
*********************************************************
***********************************************************************************************************
; 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)
*************************************************************************************************************************
上面红色部分是修改的部分,其它保持不变
运行php-fpm 和nginx
$ /usr/local/sbin/php-fpm
$ /usr/local/nginx/sbin/nginx
在niginx 的安装目录下找到html目录(默认网站目录),新建一个index.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/