zoukankan      html  css  js  c++  java
  • nginx php-fpm

    安装Nginx

    [root@node1 ~]# yum install -y nginx 

    安装PHP

    检查当前安装的PHP包

    [root@node1 ~]# yum list installed | grep php 

    如果有安装的PHP包,先删除他们

    [root@node1 ~]# yum remove php.x86_64 php-cli.x86_64 php-common.x86_64 php-gd.x86_64 php-ldap.x86_64 php-mbstring.x86_64 php-mcrypt.x86_64 php-mysql.x86_64 php-pdo.x86_64  

    配置yum源

    [root@node1 ~]# yum install epel-release
    [root@node1 ~]# rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

    安装PHP5.6.x

    [root@node1 ~]# yum install --enablerepo=remi --enablerepo=remi-php56 php php-opcache php-devel php-mbstring php-mcrypt php-mysqlnd php-phpunit-PHPUnit php-pecl-xdebug php-pecl-xhprof

    查看版本

    [root@node1 ~]# php --version

    安装PHP-fpm

    [root@node1 ~]# yum install --enablerepo=remi --enablerepo=remi-php56 php-fpm  

    配置与优化PHP-FPM

    [root@node2 ~]# vim /etc/php-fpm.d/www.conf

    完成php-fpm后,对其运行用户进行配置

    [root@node1 ~]# vim etc/php-fpm.conf
     
    修改:
    user = nginx
    group = nginx
    
    如果nginx用户不存在,那么先添加nginx用户
    [root@node1 ~]# groupadd nginx
    [root@node1 ~]# useradd -g nginx nginx

    修改nginx配置文件以支持php-fpm

    [root@node1 ~]# vim /etc/nginx/nginx.conf

    加入蓝色字体

    worker_processes  1;
    events {
        worker_connections  1024;
    }
    http {
        include       mime.types;
        default_type  application/octet-stream;
        sendfile        on;
        keepalive_timeout  65;
        server {
            listen       80;
            server_name  localhost;
            location / {
                root   html;
                index  index.html index.htm;
            location ~ .php$ {
                root html;
                fastcgi_pass 127.0.0.1:9000;    
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
    }
            }
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
        }
    }

    通过location指令,将所有以php为后缀的文件都交给127.0.0.1:9000来处理,而这里的IP地址和端口就是FastCGI进程监听的IP地址和端口。
    fastcgi_param指令指定放置PHP动态程序的主目录,也就是$fastcgi_script_name前面指定的路径,这里是/usr/local/nginx/html目录,建议将这个目录与Nginx虚拟主机指定的根目录保持一致,当然也可以不一致。
    fastcgi_params文件是FastCGI进程的一个参数配置文件,在安装Nginx后,会默认生成一个这样的文件,这里通过include指令将FastCGI参数配置文件包含了进来

    在 /usr/share/nginx/html/下创建index.php文件

    [root@node1 ~]# vim /usr/share/nginx/html/index.php
    插入以下内容
    <?php
        echo phpinfo();
    ?>

    启动php-fpm和nginx

    [root@node1 ~]# systemctl start php-fpm
    [root@node1 ~]# systemctl start nginx

    查看进程数

    [root@node1 ~]# ps aux | grep -c php-fpm

    查看监听的IP地址和端口相关信息

    [root@node1 ~]# netstat -antl|grep 9000
    [root@node1 ~]# ps -ef|grep php-cgi  

     访问http://ip地址/index.php,皆可以见到php信息了

    参考文档:

    http://www.linuxidc.com/Linux/2010-05/26149.htm
    http://www.nginx.cn/231.html
    https://www.cnblogs.com/mangguoxiansheng/p/5967745.html
    https://www.cnblogs.com/txtfashion/p/3669524.html
    http://blog.51cto.com/ixdba/806622
    http://www.thinkphp.cn/topic/48196.html


     

     

     

     

     

  • 相关阅读:
    Lambda表达式、依赖倒置
    ASP.NET vNext 概述
    Uname
    RHEL4 i386下安装rdesktop【原创】
    Taxonomy of class loader problems encountered when using Jakarta Commons Logging(转)
    How to decompile class file in Java and Eclipse
    先有的资源,能看的速度看,不能看的,抽时间看。说不定那天就真的打不开了(转)
    Google App Engine 学习和实践
    【VBA研究】VBA通过HTTP协议实现邮件轨迹跟踪查询
    js正則表達式语法
  • 原文地址:https://www.cnblogs.com/wanglan/p/8124877.html
Copyright © 2011-2022 走看看