zoukankan      html  css  js  c++  java
  • linux系统下安装配置Nginx、PHP环境

    参考地址:https://www.cnblogs.com/evai/p/5991525.html

    下载新的CentOS-Base.repo 到/etc/yum.repos.d/

    wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

    运行yum makecache生成缓存:

    yum clean all
    yum makecache
    yum update

    安装Nginx

    1.由于yum源中没有我们想要的nginx,那么我们就需要创建一个“/etc/yum.repos.d/nginx.repo”的文件,其实就是新增一个yum源。

    vim /etc/yum.repos.d/nginx.repo

    把如下内容复制进去

    [nginx]
    name=nginx repo
    baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
    gpgcheck=0
    enabled=1

    2.输入 yum list nginx 查看可安装的nginx包

    [root@iZ2zeemzju81bld21k77icZ html]# yum list nginx
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
     * base: mirrors.cloud.aliyuncs.com
     * extras: mirrors.cloud.aliyuncs.com
     * updates: mirrors.cloud.aliyuncs.com
     * webtatic: uk.repo.webtatic.com
    Installed Packages
    nginx.x86_64

    如果执行命令是这样的显示效果,表示nginx的yum源配置成功

    3.安装nginx

    yum -y install nginx

    4.启动nginx、查看启动状态

    service nginx restart
    service nginx status
    

    安装PHP7

    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

    执行命令安装php7:

    yum install php70w.x86_64 php70w-cli.x86_64 php70w-common.x86_64 php70w-gd.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64 php70w-mysql.x86_64 php70w-pdo.x86_64

    安装php-fpm:

    yum install php70w-fpm php70w-opcache

    启动php-fpm:

    systemctl start php-fpm

    修改 /etc/nginx/conf.d/default.conf 文件:

    server {
        listen       80;
        server_name  localhost;
    
        #charset koi8-r;
        #access_log  /var/log/nginx/host.access.log  main;
    
        location / {
            root   /usr/share/nginx/html;
            index  index.php index.html index.htm;
        }
    
        #error_page  404              /404.html;
    
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }
    
        # 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           /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;
        }
    
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /.ht {
        #    deny  all;
        #}
    }
    

    nginx配置位置

    /etc/nginx/nginx.conf

    php配置位置

    /etc/php.ini

    ######避免PHP信息暴露在http头中
    expose_php = Off
    
    ######设置PHP的时区
    date.timezone = PRC
    
    ######设置PHP脚本允许访问的目录(需要根据实际情况配置)
    open_basedir = /usr/share/nginx/html

    配置www.conf

    /etc/php-fpm.d/www.conf

    user = nginx

    ######设置用户和用户组
    user = nginx
    group = nginx
    
    ######设置php的session目录(所属用户和用户组都是nginx)
    php_value[session.save_handler] = files
    php_value[session.save_path] = /var/lib/php/session
    
    设置PHP监听
    ; listen = 127.0.0.1:9000   #####不建议使用

    配置php-fpm.conf

    /etc/php-fpm.conf

    ######引入www.conf文件中的配置
    include=/etc/php-fpm.d/*.conf

    4.配置文件所在地址

    php.ini             /etc/php.ini
    php加载ini文件       /etc/php.d/*.ini
    php-fpm.conf        /etc/php-fpm.conf    
    php-fpm.pid         /var/run/php-fpm/php-fpm.pid
    php-fpm启动          php-fpm

  • 相关阅读:
    Constants and Variables
    随想
    C#基础篇之语言和框架介绍
    Python基础19 实例方法 类方法 静态方法 私有变量 私有方法 属性
    Python基础18 实例变量 类变量 构造方法
    Python基础17 嵌套函数 函数类型和Lambda表达式 三大基础函数 filter() map() reduce()
    Python基础16 函数返回值 作用区域 生成器
    Python基础11 List插入,删除,替换和其他常用方法 insert() remove() pop() reverse() copy() clear() index() count()
    Python基础15 函数的定义 使用关键字参数调用 参数默认值 可变参数
    Python基础14 字典的创建修改访问和遍历 popitem() keys() values() items()
  • 原文地址:https://www.cnblogs.com/p36606jp/p/15113639.html
Copyright © 2011-2022 走看看