nginx(五)nginx与php的安装配置

时间:2023-11-10 22:41:02

经过前面学习,对nginx有个大概的了解,来配置LNMP;只要是在系统安装过程中选择安装比较齐全的包,基本上系统都能满足安装要求,下面是我一个一个测试的,基本上全部安装所需的库文件,放心安装;

[root@mgmserver ~]# rpm -qa |grep zlib
zlib-devel-1.2.3-3
zlib-1.2.3-3

[root@mgmserver tar_packet]# rpm -qa |grep openssl
openssl-0.9.8e-12.el5
openssl-devel-0.9.8e-12.el5

[root@mgmserver tar_packet]# rpm -qa |grep pcre
pcre-6.6-2.el5_1.7
pcre-devel-6.6-2.el5_1.7

[root@mgmserver tar_packet]# rpm -qa |grep gcc
compat-libgcc-296-2.96-138
compat-gcc-34-g77-3.4.6-4
gcc-c++-4.1.2-46.el5
libgcc-4.1.2-46.el5
compat-gcc-34-3.4.6-4
compat-gcc-34-c++-3.4.6-4
gcc-java-4.1.2-46.el5
gcc-4.1.2-46.el5
gccp-gfortran-4.1.2-46.el5

[root@mgmserver tar_packet]# rpm -qa |grep autoconf
autoconf-2.59-12

[root@mgmserver tar_packet]# rpm -qa |grep automake
automake-1.9.6-2.1
automake16-1.6.3-8
automake15-1.5-16
automake17-1.7.9-7
automake14-1.4p6-13

[root@mgmserver ~]# rpm -qa |grep libjpeg
libjpeg-devel-6b-37
libjpeg-6b-37

[root@mgmserver ~]# rpm -qa |grep libpng
libpng-1.2.10-7.1.el5_3.2
libpng-devel-1.2.10-7.1.el5_3.2

[root@mgmserver ~]# rpm -qa |grep freetype
freetype-2.2.1-21.el5_3
freetype-devel-2.2.1-21.el5_3

[root@mgmserver ~]# rpm -qa |grep libxml2
libxml2-python-2.6.26-2.1.2.8
libxml2-2.6.26-2.1.2.8
libxml2-devel-2.6.26-2.1.2.8

[root@mgmserver ~]# rpm -qa |grep glibc
glibc-2.5-42
glibc-devel-2.5-42
compat-glibc-2.3.4-2.26
glibc-common-2.5-42
compat-glibc-headers-2.3.4-2.26
glibc-headers-2.5-42

[root@mgmserver ~]# rpm -qa |grep glib2
glib2-2.12.3-4.el5_3.1
glib2-devel-2.12.3-4.el5_3.1

[root@mgmserver ~]# rpm -qa |grep bzip2
bzip2-devel-1.0.3-4.el5_2
bzip2-libs-1.0.3-4.el5_2
bzip2-1.0.3-4.el5_2

[root@mgmserver ~]# rpm -qa |grep ncurses
ncurses-devel-5.5-24.20060715
ncurses-5.5-24.20060715

[root@mgmserver ~]# rpm -qa |grep curl
curl-devel-7.15.5-2.1.el5_3.5
curl-7.15.5-2.1.el5_3.5

[root@mgmserver ~]# rpm -qa |grep e2fsprogs
e2fsprogs-libs-1.39-23.el5
e2fsprogs-1.39-23.el5
e2fsprogs-devel-1.39-23.el5

[root@mgmserver ~]# rpm -qa |grep krb5
pam_krb5-2.2.14-10
krb5-auth-dialog-0.7-1
krb5-libs-1.6.1-36.el5
krb5-workstation-1.6.1-36.el5
krb5-devel-1.6.1-36.el5

[root@mgmserver ~]# rpm -qa |grep libidn
libidn-0.6.5-1.1
libidn-devel-0.6.5-1.1

[root@mgmserver ~]# rpm -qa |grep nss_ldap
nss_ldap-253-21.el5

openldap 这个库缺少 
[root@mgmserver ~]#yum install openldap* 

[root@mgmserver ~]# rpm -qa |grep openldap 
openldap-clients-2.3.43-3.el5
openldap-2.3.43-3.el5
openldap-devel-2.3.43-3.el5
openldap-servers-2.3.43-3.el5
openldap-servers-sql-2.3.43-3.el5
openldap-servers-overlays-2.3.43-3.el5

1、安装LNMP 所需的安装包有点多,要耐心.......,下载的链接张老师的博客上有:

http://sysoev.ru/nginx/nginx-0.8.46.tar.gz

#nginx主程序包

http://www.php.net/get/php-5.2.14.tar.gz/from/this/mirror

#PHP主程序包

 http://php-fpm.org/downloads/php-5.2.14-fpm-0.5.14.diff.gz

#PHP的FastCGI进程管理补丁包

http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.3-m3.tar.gz/from/http://mysql.he.net/

#mysql主程序包

http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz

libiconv库是一个基于GNU协议的开源库,主要是解决多语言编码处理转换等应用问题;
由于历史原因,国际化的文字常常由于语言或者国家的原因使用不同的编码。随着互联网时代的到来,通过互联网进行文字交流也逐渐增多:浏览外国的网站,这个时候字符编码的转换变得尤为重要。这带来了一个问题,就是许多字符在某一种编码方式中没有。为了解决这种混乱,Unicode的编码方式被建立。 Unicode是一种超级编码包含了所有这些编码的字符集,因此一些新的文本格式像XML的默认编码方式就是Unicode.
但是很多老式的计算机还在使用当地的传统的字符编码方式。而一些程序,例如邮件程序和浏览器必须能在这些不同的用户编码之间作转换。其他的一些程序则内置支持Unicode,以顺利支持国际化的处理,但是仍然有在Unicode和其他的传统编码之间转换的需求。GNU的libiconv就是为这两种应用设计的编码转换库。libiconv库为需要做转换的应用提供了一个iconv()的函数,以实现一个字符编码到另一个字符编码的转换。

 

http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz?modtime=1171868460&big_mirror=0

#安全线程加密库主程序包

http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz?modtime=1194463373&big_mirror=0

#Mcrypt是一个功能强大的加密算法扩展库,它包括有22种算法


http://pecl.php.net/get/memcache-2.2.5.tgz

#memcache是一个高性能的分布式的内存对象缓存系统,通过在内存里维护一个统一的巨大的hash表,它能够用来存储各种格式的数据,包括图像、视频、文件以及数据库检索的结果等。Memcache是danga.com的一个项目,最早是为 LiveJournal 服务的,最初为了加速 LiveJournal 访问速度而开发的,后来被很多大型的网站采用。目前全世界不少人使用这个缓存项目来构建自己大负载的网站,来分担数据库的压力。起初作者编写它可能是为了提高动态网页应用,为了减轻数据库检索的压力,来做的这个缓存系统。它的缓存是一种分布式的,也就是可以允许不同主机上的多个用户同时访问这个缓存系统, 这种方法不仅解决了共享内存只能是单机的弊端,同时也解决了数据库检索的压力,最大的优点是提高了访问获取数据的速度!基于memcache作者对分布式 cache的理解和解决方案。 memcache完全可以用到其他地方 比如分布式数据库, 分布式计算等领域。 
 

http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz?modtime=1175740843&big_mirror=0

#Mhash扩展库,Mhash扩展库支持12种混编算法

ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.10.tar.gz

#正则表达式扩展主程序包

http://bart.eaccelerator.net/source/0.9.6.1/eaccelerator-0.9.6.1.tar.bz2

#eAccelerator是一个*开放源码php加速器,优化和动态内容缓存,提高了php脚本的缓存性能,使得PHP脚本在编译的状态下,对服务器的开销几乎完全消除。 它还有对脚本起优化作用,以加快其执行效率。使您的PHP程序代码执效率能提高1-10倍;

http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz

#PDO 是 PHP 数据对象的缩写, 是一种访问数据库的更便捷、安全的途径。通过该方式,数据库开发者可以更方便地写出移植性较高的代码。PDO 并不是类似于 PearDB 的数据库抽象层,而 更像一种采用了统一 API (应用编程接口)的数据访问层。

如何启用PDO?要启用 PDO 配置,须打开 pdo 、pdo_sqlite、pdo_mysql等所的扩展模块

http://blog.s135.com/soft/linux/nginx_php/imagick/ImageMagick.tar.gz

#是一个免费的创建、编辑、合成图片的软件。它可以读取、转换、写入多种格式的图片。图片切割、颜色替换、各种效果的应用,图片的旋转、组合,文本,直线,多边形,椭圆,曲线,附加到图片伸展旋转。ImageMagick是免费软件:全部源码开放,可以*使用,复制,修改,发布。它遵守GPL许可协议。它可以运行于大多数的操作系统。ImageMagick的大多数功能的使用都来源于命令行工具。通常来说,它可以支持以下程序语言: Perl, C, C++, Python, PHP, Ruby, Java

http://pecl.php.net/get/imagick-2.3.0.tgz

#一般用php处理图片都是使用GD库或者GD2的函数库,一般编译php环境都会搭上GD库,大多数开源程序也是用GD来处理图片的,但是它只能现实诸如调整大小、增加水印等基础功能,要想用GD来做复杂图形是非常困难的。

基于命令行的图像处理软件ImageMagick,能实现非常丰富的功能。如果服务器上安装了ImageMagick,php脚本可以使用 shell命令来完成,也可以用php的原生函数库Imagick或者MagickWandForPHP函数来调用ImageMagick软件来实现。

因为Linux系统下PHP往往没有执行shell的权限,直接用shell来操作ImageMagick不太可能,综合考虑,Imagick函数库连接到ImageMagick软件比较好,而且是面向对象方式的。

 

2、安装php(fastcgi模式)

(1)、安装php所需的支持库

[root@mgmserver tar_packet]# tar -zxvf libiconv-1.13.1.tar.gz -C ../install_packet/
[root@mgmserver libiconv-1.13.1]# ./configure --prefix=/usr/local
[root@mgmserver libiconv-1.13.1]# make
[root@mgmserver libiconv-1.13.1]# make install

[root@mgmserver tar_packet]# tar -zxvf libmcrypt-2.5.8.tar.gz -C ../install_packet/

[root@mgmserver libmcrypt-2.5.8]# ./configure

[root@mgmserver libmcrypt-2.5.8]# make

[root@mgmserver libmcrypt-2.5.8]# make install
[root@mgmserver libltdl]# /sbin/ldconfig      (配置动态连接器(ld)运行时邦定)
[root@mgmserver libltdl]# cd libltdl/
[root@mgmserver libltdl]# ./configure --enable-ltdl-install
[root@mgmserver libltdl]# make

[root@mgmserver libltdl]# make install

[root@mgmserver tar_packet]# tar -zxvf mhash-0.9.9.9.tar.gz -C ../install_packet/
[root@mgmserver install_packet]# cd mhash-0.9.9.9/

[root@mgmserver mhash-0.9.9.9]# ./configure
[root@mgmserver mhash-0.9.9.9]# make
[root@mgmserver mhash-0.9.9.9]# make install

[root@server5 mhash-0.9.9.9]# ln -s /usr/local/lib/* /usr/lib     
(这一步不用做了 ,做完成上面步骤后/usr/lib下面已经存在了)

[root@localhost install_packet]# ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
[root@localhost install_packet]# ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
[root@localhost install_packet]# ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
[root@localhost install_packet]# ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8

[root@localhost install_packet]# ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
[root@localhost install_packet]# ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
[root@localhost install_packet]# ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
[root@localhost install_packet]# ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
[root@localhost install_packet]# ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1

[root@localhost install_packet]# ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config

[root@mgmserver tar_packet]# tar -zxvf mcrypt-2.6.8.tar.gz -C ../install_packet/
[root@mgmserver mcrypt-2.6.8]# /sbin/ldconfig

[root@mgmserver mcrypt-2.6.8]# ./configure
[
root@mgmserver mcrypt-2.6.8]# make
[root@mgmserver mcrypt-2.6.8]# make install

(2)、安装mysql

[root@mgmserver tar_packet]# groupadd mysql
[root@mgmserver tar_packet]# useradd -g mysql mysql
[root@mgmserver tar_packet]#tar -zxvf mysql-5.5.3-m3.tar.gz -C ../install_packet/

[root@mgmserver mysql-5.5.3-m3]# ./configure --prefix=/usr/local/mysql --enable-assembler --with-charset=utf8 --with-extra-charsets=complex --enable-thread-safe-client --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile --with-plugins=innobase --with-mysqld-ldflags=-all-static --with-client-ldflags=-all-static --with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock

[root@mgmserver mysql-5.5.3-m3]# make
[root@mgmserver mysql-5.5.3-m3]# make install
[root@mgmserver mysql-5.5.3-m3]# cp support-files/my-large.cnf /etc/my.cnf
[root@mgmserver mysql]# pwd
/usr/local/mysql

 [root@mgmserver mysql]# bin/mysql_install_db --user=mysql
Installing MySQL system tables...
100903 13:30:41 [ERROR] /usr/local/mysql/libexec/mysqld: unknown variable 'thread_concurren                 cy=8'
100903 13:30:41 [ERROR] Aborting

100903 13:30:41 [Note] /usr/local/mysql/libexec/mysqld: Shutdown complete

.......

mysql 初始化报错,发现网上有哥们已经解决了这个问题,实在是强大,原因是my.cnf中有一行:

thread_concurrency = 8

thread_concurrency这个变量,意思是并发的线程数,并且根据给的解释是该参数取值为服务器逻辑CPU数量×2,而如果每颗物理CPU又支持H.T超线程,所以实际取值为4 × 2 = 8。而我这个机器是ADM闪龙3000 单核的CPU,并不符合它的要求,所以它提示“unknown variable ‘thread_concurrency=8′”是个未知变量。对my.cnf做一些修改,把’thread_concurrency=8′注释掉
 

nginx(五)nginx与php的安装配置

重新初始化OK

[root@mgmserver mysql]# bin/mysql_install_db --user=mysql
Installing MySQL system tables...
OK
Filling help tables...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

...........

[root@localhost mysql]# chown -R root .
[root@localhost mysql]# chown -R mysql var
[root@localhost mysql]# chgrp -R mysql .

[root@mgmserver mysql]# cp share/mysql/mysql.server /etc/init.d/mysqld
[root@mgmserver mysql]# chkconfig --add mysqld
[root@mgmserver mysql]# cd /etc/init.d/
[root@mgmserver init.d]# chmod +x mysqld
[root@mgmserver init.d]# chkconfig --list mysqld
mysqld          0:关闭  1:关闭  2:启用  3:启用  4:启用  5:启用  6:关闭
[root@mgmserver init.d]# service mysqld start
Starting MySQL                                             [确定]

[root@mgmserver init.d]# cp /usr/local/mysql/bin/* /sbin/
[root@mgmserver init.d]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.3-m3-log Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)

mysql> exit
Bye

[root@mgmserver init.d]# mysqladmin -u root -h localhost password 'mysql'
[root@mgmserver init.d]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@mgmserver init.d]#
[root@mgmserver init.d]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.5.3-m3-log Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;

(3)、编译安装pHP (fastcgi模式)

[root@mgmserver tar_packet]# tar -zxvf php-5.2.14.tar.gz -C ../install_packet/

[root@mgmserver php-5.2.14]# pwd
/home/install_packet/php-5.2.14

[root@localhost install_packet]# gzip -cd php-5.2.14-fpm-0.5.14.diff.gz |patch -d php-5.2.14 -p1

[root@mgmserver php-5.2.14]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir=/usr/local --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 --with-curlwrappers --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-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap

[root@mgmserver php-5.2.14]# make ZEND_EXTRA_LIBS='-liconv'

[root@mgmserver php-5.2.14]# make install

[root@mgmserver php-5.2.14]# cp php.ini-dist /usr/local/php/etc/php.ini

 (4)、安装PHP扩展

[root@mgmserver tar_packet]# tar -zxvf memcache-2.2.5.tgz -C ../install_packet/
[root@mgmserver memcache-2.2.5]# /usr/local/php/bin/phpize
[root@mgmserver memcache-2.2.5]# ./configure --with-php-config=/usr/local/php/bin/php-config
[root@mgmserver memcache-2.2.5]# make
[root@mgmserver memcache-2.2.5]# make install
Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/

[root@mgmserver tar_packet]# tar -jxvf eaccelerator-0.9.6.1.tar.bz2 -C ../install_packet/
[root@mgmserver install_packet]# cd eaccelerator-0.9.6.1/
[root@mgmserver eaccelerator-0.9.6.1]# /usr/local/php/bin/phpize
[root@mgmserver eaccelerator-0.9.6.1]# ./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config
[root@mgmserver eaccelerator-0.9.6.1]# make
[root@mgmserver eaccelerator-0.9.6.1]# make install
Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/

[root@mgmserver tar_packet]# tar -zxvf PDO_MYSQL-1.0.2.tgz -C ../install_packet/
[root@mgmserver install_packet]# cd PDO_MYSQL-1.0.2/
[root@mgmserver PDO_MYSQL-1.0.2]# /usr/local/php/bin/phpize
[root@mgmserver PDO_MYSQL-1.0.2]# ./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-
mysql=/usr/local/mysql
[root@mgmserver PDO_MYSQL-1.0.2]# make
[root@mgmserver PDO_MYSQL-1.0.2]# make install
Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613

[root@mgmserver tar_packet]# tar -zxvf ImageMagick.tar.gz -C ../install_packet/
[root@mgmserver ImageMagick-6.5.1-2]# ./configure
[root@mgmserver ImageMagick-6.5.1-2]# make
[root@mgmserver ImageMagick-6.5.1-2]# make install

[root@mgmserver tar_packet]# tar -zxvf imagick-2.3.0.tgz -C ../install_packet/
[root@mgmserver install_packet]# cd imagick-2.3.0/
[root@mgmserver imagick-2.3.0]# /usr/local/php/bin/phpize
[root@mgmserver imagick-2.3.0]# ./configure --with-php-config=/usr/local/php/bin/php-config
[root@mgmserver imagick-2.3.0]# make
[root@mgmserver imagick-2.3.0]# make install
Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/

(5)、修改php.ini文件

找到491行的extension_dir = "./"
修改为  extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613" 指定模块所在的位置;
在这行后面加上
    493  extension = "imagick.so"
    494  extension = " memcache.so"
    495  extension = "pdo_mysql.so"
在 101行处
    修改 output_buffering = Off为 output_buffering = On
把523 处的注释去掉, cgi.fix_pathinfo=0 防止nginx文件类型错误解析漏洞

6、配置php加速eaccelerator

创建缓存文件夹;

[root@mgmserver local]# mkdir eaccelerator_cache

在php.ini配置文件末尾加上如下:

1290 [eaccelerator]
   1291   extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so
   1292   eaccelerator.shm_size="32"
   1293   eaccelerator.cache_dir="/usr/local/eaccelerator_cache"
   1294   eaccelerator.enable="1"
   1295   eaccelerator.optimizer="1"
   1296   eaccelerator.check_mtime="1"
   1297   eaccelerator.debug="0"
   1298   eaccelerator.filter=""
   1299   eaccelerator.shm_max="0"
   1300   eaccelerator.shm_ttl="3600"
   1301   eaccelerator.shm_prune_period="360"
   1302   eaccelerator.shm_only="0"
   1303   eaccelerator.compress="1"
   1304   eaccelerator.compress_level="9"

(7)、悲剧了,空余的机器被拿去用了,只好换个机器,创建www 用户和组,及两个虚拟主机域名目录www.nginx.com与web.nginx.com

[root@mgmserver ~]# groupadd www
[root@mgmserver ~]# useradd -g www www

[root@nginx ~]# mkdir -p /web/htdocs/www.nginx.com
[root@nginx ~]# chown -R www:www /web/htdocs/www.nginx.com

[root@nginx ~]# mkdir -p /web/htdocs/web.nginx.com
[root@nginx ~]# chown -R www:www /web/htdocs/web.nginx.com/
nginx(五)nginx与php的安装配置


 8、修改php-fpm配置文件,黄色标记的是修改值

1 <?xml version="1.0" ?>
      2 <configuration>
      3
      4         All relative paths in this config are relative to php's install prefix
      5
      6         <section name="global_options">
      7
      8                 Pid file
      9                 <value name="pid_file">/usr/local/php/logs/php-fpm.pid</value>
     10
     11                 Error log file
     12                 <value name="error_log">/usr/local/php/logs/php-fpm.log</value>
     13
     14                 Log level
     15                 <value name="log_level">notice</value>
     16
     17                 When this amount of php processes exited with SIGSEGV or SIGBUS ...
     18                 <value name="emergency_restart_threshold">10</value>
     19
     20                 ... in a less than this interval of time, a graceful restart will be initiated.
     21                 Useful to work around accidental curruptions in accelerator's shared memory.
     22                 <value name="emergency_restart_interval">1m</value>
     23
     24                 Time limit on waiting child's reaction on signals from master
     25                 <value name="process_control_timeout">5s</value>
     26
     27                 Set to 'no' to debug fpm
     28                 <value name="daemonize">yes</value>
     29
     30         </section>
     31
     32         <workers>
     33
     34                 <section name="pool">
     35
     36                         Name of pool. Used in logs and stats.
     37                         <value name="name">default</value>
     38
     39                         Address to accept fastcgi requests on.
     40                         Valid syntax is 'ip.ad.re.ss:port' or just 'port' or '/path/to/unix/socket'
     41                         <value name="listen_address">127.0.0.1:9000</value>
     42
     43                         <value name="listen_options">
    44
     45                                 Set listen(2) backlog
     46                                 <value name="backlog">-1</value>
     47
     48                                 Set permissions for unix socket, if one used.
     49                                 In Linux read/write permissions must be set in order to allow connections from web server.
     50                                 Many BSD-derrived systems allow connections regardless of permissions.
     51                                 <value name="owner"></value>
     52                                 <value name="group"></value>
     53                                 <value name="mode">0666</value>
     54                         </value>
     55
     56                         Additional php.ini defines, specific to this pool of workers.
     57                         <value name="php_defines">
     58                 <!--            <value name="sendmail_path">/usr/sbin/sendmail -t -i</value>            -->
     59                 <!--            <value name="display_errors">0</value>                                                          -->
     60                         </value>
     61
     62                         Unix user of processes
     63                 <!--    <value name="user">www</value>                          -->
     64
     65                         Unix group of processes
     66                 <!--    <value name="group">www</value>         -->
     67
     68                         Process manager settings
     69                         <value name="pm">
     70
     71                                 Sets style of controling worker process count.
     72                                 Valid values are 'static' and 'apache-like'
     73                                 <value name="style">static</value>
     74
     75                                 Sets the limit on the number of simultaneous requests that will be served.
     76                                 Equivalent to Apache MaxClients directive.
     77                                 Equivalent to PHP_FCGI_CHILDREN environment in original php.fcgi
     78                                 Used with any pm_style.
     79                                 <value name="max_children">64</value>(如果机器内存小于3G,可以设置64个进程)
     80
     81                                 Settings group for 'apache-like' pm style
     82                                 <value name="apache_like">
     83
     84                                         Sets the number of server processes created on startup.
     85                                         Used only when 'apache-like' pm_style is selected
     86                                         <value name="StartServers">20</value>
    87
     88                                         Sets the desired minimum number of idle server processes.
     89                                         Used only when 'apache-like' pm_style is selected
     90                                         <value name="MinSpareServers">5</value>
     91
     92                                         Sets the desired maximum number of idle server processes.
     93                                         Used only when 'apache-like' pm_style is selected
     94                                         <value name="MaxSpareServers">35</value>
     95
     96                                 </value>
     97
     98                         </value>
     99
    100                         The timeout (in seconds) for serving a single request after which the worker process will be terminated
    101                         Should be used when 'max_execution_time' ini option does not stop script execution for some reason
    102                         '0s' means 'off'
    103                         <value name="request_terminate_timeout">0s</value>
    104
    105                         The timeout (in seconds) for serving of single request after which a php backtrace will be dumped to slow.log file
    106                         '0s' means 'off'
    107                         <value name="request_slowlog_timeout">0s</value>
    108
    109                         The log file for slow requests
    110                         <value name="slowlog">logs/slow.log</value>
    111
    112                         Set open file desc rlimit
    113                         <value name="rlimit_files">65535</value>
    114
    115                         Set max core size rlimit
    116                         <value name="rlimit_core">0</value>
    117
    118                         Chroot to this directory at the start, absolute path
    119                         <value name="chroot"></value>
    120
    121                         Chdir to this directory at the start, absolute path
    122                         <value name="chdir"></value>
    123
    124                         Redirect workers' stdout and stderr into main error log.
    125                         If not set, they will be redirected to /dev/null, according to FastCGI specs
    126                         <value name="catch_workers_output">yes</value>
    127
    128                         How much requests each process should execute before respawn.
    129                         Useful to work around memory leaks in 3rd party libraries.
    130                         For endless request processing please specify 0
    131                         Equivalent to PHP_FCGI_MAX_REQUESTS
    132                         <value name="max_requests">500</value>
    133
    134                         Comma separated list of ipv4 addresses of FastCGI clients that allowed to connect.
    135                         Equivalent to FCGI_WEB_SERVER_ADDRS environment in original php.fcgi (5.2.2+)
    136                         Makes sense only with AF_INET listening socket.
    137                         <value name="allowed_clients">127.0.0.1</value>
    138
    139                         Pass environment variables like LD_LIBRARY_PATH
    140                         All $VARIABLEs are taken from current environment
    141                         <value name="environment">
    142                                 <value name="HOSTNAME">$HOSTNAME</value>
    143                                 <value name="PATH">/usr/local/bin:/usr/bin:/bin</value>
    144                                 <value name="TMP">/tmp</value>
    145                                 <value name="TMPDIR">/tmp</value>
    146                                 <value name="TEMP">/tmp</value>
    147                                 <value name="OSTYPE">$OSTYPE</value>
    148                                 <value name="MACHTYPE">$MACHTYPE</value>
    149                                 <value name="MALLOC_CHECK_">2</value>
    150                         </value>
    151
    152                 </section>
    153
    154         </workers>
    155
    156 </configuration>

(9)、启动php-cgi进程,监听127.0.0.1的9000端口,进程数为64

把配置文件的63行和66行修改如下:

62                         Unix user of processes
     63                   <value name="user">www</value>                      
     64
     65                         Unix group of processes
     66                  <value name="group">www</value>

切记要把63行和66行的注释符号去掉不然在启动时会出错的!

[ERROR] fpm_unix_conf_wp(), line 124: please specify user and group other than root, pool 'default'

[root@nginx ~]# /usr/local/php/sbin/php-fpm start
Starting php_fpm . done

[root@nginx nginx]# netstat -ntpl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
tcp        0      0 127.0.0.1:2208              0.0.0.0:*                   LISTEN      2630/hpiod
tcp        0      0 0.0.0.0:833                 0.0.0.0:*                   LISTEN      2347/rpc.statd
tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      5285/php-cgi

........

3、安装nginx

(1)、安装nginx及所需要的pcre库

[root@nginx pcre-8.10]# ./configure
[root@nginx pcre-8.10]# make
[root@nginx pcre-8.10]# make install

[root@nginx install_packet]# cd nginx-0.8.48/
[root@nginx nginx-0.8.48]# ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
[root@nginx nginx-0.8.48]#make
[root@nginx nginx-0.8.48]#make install

(2)、创建nginx的日志文件
[root@nginx /]# mkdir -p web/nginxlogs
[root@nginx /]# chmod +w web/nginxlogs/
[root@nginx /]# chown -R www:www web/nginxlogs/

(3)、修改nginx的配置文件如下:

1
      2 user www www;
      3 worker_processes  1;
      4 error_log    /web/nginxlogs/error.log  crit;
      5 pid        /usr/local/nginx/nginx.pid;
      6 worker_rlimit_nofile 65535;
      7 events {
      8     use epoll;
      9     worker_connections  1024;
     10 }
     11
     12
     13 http {
     14     include       mime.types;
     15     default_type  application/octet-stream;
     16
     17     server_names_hash_bucket_size 128;
     18     client_header_buffer_size 32k;
     19     large_client_header_buffers 4 32k;
     20     client_max_body_size 8m;
     21
     22
     23     sendfile        on;
     24     tcp_nopush     on;
     25
     26     #keepalive_timeout  0;
     27     keepalive_timeout  60;
     28     tcp_nodelay    on;
     29
     30     fastcgi_connect_timeout 300;
     31     fastcgi_send_timeout    300;
     32     fastcgi_read_timeout     300;
     33     fastcgi_buffer_size     64k;
     34     fastcgi_buffers       4 64k;
     35     fastcgi_busy_buffers_size 128k;
     36     fastcgi_temp_file_write_size 128k;
     37
     38     gzip  on;
     39     gzip_min_length        1k;
     40     gzip_buffers      4    16k;
     41     gzip_http_version      1.0;
     42     gzip_comp_level  2;
     43     gzip_types  text/plain application/x-javascript text/css application/xml;   
     44     gzip_vary on;
     45
     46     server {
     47         listen       80;
     48         server_name  www.nginx.com;
     49         root   /web/htdocs/www.nginx.com;
     50         index  index.html index.htm index.php;
     51
     52         location ~.*\.(php|php5)?$ {
     53              fastcgi_pass   127.0.0.1:9000;
     54              fastcgi_index  index.php;
     55              include        fastcgi.conf;
     56         }
     57
     58         location ~.*\.(gif|jpg|jpeg|png|bmp|swf)$
     59         {
     60             expires    30d;
     61         }
     62         location ~.*\.(js|css)$
     63         {
     64             expires    1h;
     65         }
     66         log_format  wwwaccess  '$remote_addr - $remote_user [$time_local] "$request" '
     67                             '$status $body_bytes_sent "$http_referer" '
     68                             '"$http_user_agent" $http_x_forwarded_for';
     69         access_log  /web/nginxlogs/wwwaccess.log  wwwaccess;
     70 }
     71
     72
     73    server {
     74          listen       80;
     75          server_name  web.nginx.com;
     76          root   /web/htdocs/web.nginx.com;
     77          index  index.html index.htm index.php;
     78          location ~.*\.(php|php5)?$
     79          {
     80          fastcgi_pass   127.0.0.1:9000;
     81          fastcgi_index  index.php;
     82          include        fastcgi.conf;
     83          }
     84     log_format  webaccess  '$remote_addr - $remote_user [$time_local] "$request"'

85                         '$status $body_bytes_sent "$http_referer"'
     86                         '"$http_user_agent" $http_x_forwarded_for';
     87      access_log  /web/nginxlogs/webaccess.log  webaccess;
     88     }
     89 }

(4)、保持conf/下fastcgi.conf配置文件不变就可以了

(5)、启动nginx

[root@nginx nginx]#/usr/

[root@nginx nginx]# /usr/local/nginx/sbin/nginx
(6)、开机启动nginx 与php

[root@nginx nginxlogs]# vi /etc/rc.local

ulimit -SHn 65535
/usr/local/php/sbin/php-fpm start
/usr/local/nginx/sbin/nginx

(7)修改文件中先检查配置文件是否正确,然后在启动

[root@nginx nginxlogs]# /usr/local/nginx/sbin/nginx -t
the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
configuration file /usr/local/nginx/conf/nginx.conf test is successful

[root@nginx nginxlogs]# kill -HUP `cat /usr/local/nginx/nginx.pid`
或者

[root@nginx nginxlogs]# /usr/loca/nginx/sbin/nginx -s reload

4、测试

在www.nginx.com的文档目录中

[root@nginx www.nginx.com]# vi index.php/
<?php  phpinfo(); ?>
类似的在web.nginx.com中新建一个index.php文件:

nginx(五)nginx与php的安装配置

nginx(五)nginx与php的安装配置

基本上算是完成了涨老师的实验配置