• RHEL 7.4 下yum安装配置nginx与php


    环境: RHEL7.4 最小化安装

    nginx版本:nginx/1.18.0

    php版本:PHP Version 5.4.16

    增加额外nginx php最新资源库

    rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
    
    rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm 
    
    rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm 

    # 默认情况下,CentOS的官方资源是没有php-fpm的, 但我们可以从Remi的RPM资源中获得,它依赖于EPEL资源。我们可以这样增加两个资源库

    1.安装nginx

    yum install nginx

    安装完成后可以启动nginx,在浏览器里面访问,查看nginx是否安装成功。端口默认为80。

    systemctl start nginx  
    nginx中yum安装的默认网站根目录在/usr/share/nginx/html 

    2.安装PHP和PHP-FPM:

    yum install php php-fpm  

     # 启动php-fpm  

     systemctl start php-fpm 

    由于最新版本的php 已经集成了php-fpm,故只需安装php即可。

    3.将MySQL与php 关联起来

    可以通过yum install mariadb mariadb-server 安装  
    yum install php-gd php-mysql php-mbstring php-xml php-mcrypt  php-imap php-odbc php-pear php -xmlrpc  

     4.配置nginx与php一起工作

    Nginx+FastCGI运行原理
    Nginx不支持对外部程序的直接调用或者解析,所有的外部程序(包括PHP)必须通过FastCGI接口来调用。FastCGI接口在Linux下是socket,(这个socket可以是文件socket,也可以是ip socket)。为了调用CGI程序,还需要一个FastCGI的wrapper(wrapper可以理解为用于启动另一个程序的程序),这个wrapper绑定在某个固定socket上,如端口或者文件socket。当Nginx将CGI请求发送给这个socket的时候,通过FastCGI接口,wrapper接纳到请求,然后派生出一个新的线程,这个线程调用解释器或者外部程序处理脚本并读取返回数据;接着,wrapper再将返回的数据通过FastCGI接口,沿着固定的socket传递给Nginx;最后,Nginx将返回的数据发送给客户端,这就是Nginx+FastCGI的整个运作过程。详细的过程,如下图所示:

     5.修改nginx配置:

    注意:1.18版本的nginx,默认配置文件是default.conf

    vi /etc/nginx/conf.d/default.conf

      1)找到第一个location中的这一行

              index  index.html index.htm;

             修改为:

            index  index.php index.html index.htm; #添加index.php

             2)  

                   把FastCGI server这行下面的location的注释去掉,并修改成下面这样子

         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

         #

         location ~ .php$ {

             root            /usr/share/nginx/html;  #网站根目录

             fastcgi_pass   127.0.0.1:9000;

             fastcgi_index  index.php;

             fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

             include        fastcgi_params;

         }

    service nginx restart   #重启nginx

    service php-fpm start   #开启php-fpm

    6.测试nginx与php是否正常

    在网站根目录新建index.php文件

    vim /usr/share/nginx/html/info.php

    文件内容如下:

    <?php    
    phpinfo();    
    ?>  

    访问测试:http://192.168.24.100/info.php

  • 相关阅读:
    Spring Boot中的那些生命周期和其中的可扩展点(转)
    mongodb,redis,mysql的区别和具体应用场景(转)
    linux相关知识
    docker安装应用整理
    SpEL表达式总结(转)
    An association from the table user_ product refers to an unmapped class: com. hiber.pojo. User
    LoadRunner安装时提示缺少C++ 2005 SP1(x86)插件
    Web框架,Hibernate向数据库插入数据,数据库没有值怎么办?
    数据库忘记原来的密码
    在线手机验证码免费查验接收
  • 原文地址:https://www.cnblogs.com/yds941268778/p/12885980.html
Copyright © 2020-2023  润新知