网站地图    收藏   

主页 > 后端 > php进阶知识 >

web服务器Nginx安装PHP-FPM的方法以及php-fpm的优化配置

来源:未知    时间:2014-12-11 00:58 作者:xxadmin 阅读:

[导读] 一.下载安装包 下载php [root@test~]#wgethttp://cn2.php.net/distributions/php-5.5.4.tar.bz2 二.配置安装环境 strong[root@test~]#yum-yinstallgccautomakeautoconflibtoolmake [root@test~]#yum-yinstallgccgcc-c++glibc [root@test~]#yum-...

一.下载安装包

下载php
[root@test ~]# wget http://cn2.php.net/distributions/php-5.5.4.tar.bz2

二.配置安装环境

<strong>[root@test ~]# yum -y install gcc automake autoconf libtool make
[root@test ~]# yum -y install gcc gcc-c++ glibc
[root@test ~]# yum -y install libmcrypt-devel mhash-devel libxslt-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel<\>

三.编译安装php和php-fpm
1.编译
[root@test ~]# tar jxfv php-5.5.4.tar.bz2
[root@test ~]# cd php-5.5.4
[root@test php-5.5.4]# ./configure --prefix=/usr/local/php  --enable-fpm --enable-mbstring --disable-pdo --with-curl --disable-debug  --disable-rpath --enable-inline-optimization --with-bz2  --with-zlib --enable-sockets --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex --with-mhash --enable-zip --with-pcre-regex --with-mysql --with-mysqli --with-gd --with-jpeg-dir --with-config-file-path=/etc
[root@test php-5.5.4]# make all install
2.编辑php-fpm.conf文件
[root@test ~]# cd /usr/local/php/etc/
[root@test etc]# cp php-fpm.conf.default php-fpm.conf
设置fastcgi进程的用户和用户组,需要跟Nginx的配置文件中保持一致 
user = nginx 
group = nginx
设置用于设置php-fpm对打开文件描述符的限制 
rlimit_files = 65536
标签allowed_clients用于设置允许访问Fastcgi进程解析器的IP地址 
listen.allowed_clients = 127.0.0.1
四.配置Nginx来支持PHP
[root@test ~]# vim /etc\inx\inx.conf
# pass the PHP scripts to FastCGI server listening on 127 . 0 . 0 . 1 : 9000 

server { 
        listen 80 ; 
        server_name www.abc.com ; 
         root /usr\ml/abc/ ; 
        location / { 
        index index.html index.php ; 
        } 
location ~ \.php$ { 
         fastcgi_pass 127 . 0 . 0 . 1 : 9000 ; 
         fastcgi_index index.php ; 
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name ; 
         include fastcgi_params ; 
         } 
}

1.启动服务

[root@test ~]# killall nginx

[root@test ~]# /usr/sbin\inx

[root@test ~]# /usr/local/php/sbin/php-fpm
http://www.abc.com/index.php 就能看PHP了
五.优化Nginx中FastCGI参数实例
  在配置完Nginx+FastCGI之后,为了保证Nginx下PHP环境的高速稳定运行,需要添加一些FastCGI优化指令。
  将代码添加到Nginx主配置文件HTTP层级
 
       fastcgi_cache_path /usr/ local inx/fastcgi_cache levels= 1 : 2 keys_zone=TEST: 10m inactive 
= 5m ; 
        fastcgi_connect_timeout 300 ; 
        fastcgi_send_timeout 300 ; 
        fastcgi_read_timeout 300 ; 
        fastcgi_buffer_size 64k ; 
        fastcgi_buffers 4 64k ; 
        fastcgi_busy_buffers_size 128k ; 
        fastcgi_temp_file_write_size 128k ; 
        fastcgi_cache TEST ; 
        fastcgi_cache_valid 200 302 1h ; 
        fastcgi_cache_valid 301 1d ; 
        fastcgi_cache_valid any 1m ;

第一行代码是为FastCGI缓存指定一个文件路径、目录结构等级、关键字区域存储时间和非活动删除时间。
  fastcgi_connect_timeout指定连接到后端FastCGI的超时时间。
  fastcgi)send-timeout指定向FastCGI传送请求的超时时间,这个值是已经完成两次握手后向FastCGI应答的超时时间。
  fastcgi_read_timeout指定接收FastCGI应答的超时时间,这个值是已经完成两次握手后接收FastCGI应答的超时时间。
  fastcgi_buffer_size用于指定读取FastCGI应答第一部分需要多大的缓冲区。
  fastcgi_buffers指定本地需要用多少和多大的缓冲区来缓冲FastCGI的应答请求。
  fastcgi)busy_buffers_size的默认值是fastcgi_buffers的两倍。
  fastcgi_temp_file_write_size表示在写入缓存文件时使用多大的数据块,默认值是fastcgi_buffers的两倍。
  fastcgi_cache表示开启FastCGI缓冲并为其指定一个名称。
  fasrcgi_cache_valid用来指定应答代码的缓冲时间。 

自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习

京ICP备14009008号-1@版权所有www.zixuephp.com

网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com

添加评论