字节跳动Tiktok团队北上广深杭急招前后端开发,绿色内推邮箱:sunmaoyu@bytedance.com

windows本地配置php(yii)+nginx+fastcgi

一. 配置nginx支持php

官网下载nginx。

nginx.conf配置做如下更改:

    # yii框架
    server {
        charset utf-8;
        client_max_body_size 128M;

        listen 80; ## listen for ipv4
        #listen [::]:80 default_server ipv6only=on; ## listen for ipv6

        server_name www.yii.com;
        root        G:/demo/yii/basic/web;
        index       index.php;

        access_log  G:/demo/yii/basic/log/access.log;
        error_log   G:/demo/yii/basic/log/error.log debug;

        location / {
            # Redirect everything that isn't a real file to index.php
            try_files $uri $uri/ /index.php$is_args$args;
        }

        # uncomment to avoid processing of calls to non-existing static files by Yii
        #location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
        #    try_files $uri =404;
        #}
        #error_page 404 /404.html;

        # deny accessing php files for the /assets directory
        location ~ ^/assets/.*\.php$ {
            deny all;
        }
        
        location ~ \.php$ {
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_pass 127.0.0.1:9000;
            #fastcgi_pass unix:/var/run/php5-fpm.sock;
            try_files $uri =404;
        }

        location ~* /\. {
            deny all;
        }
    }

 配置好后重启nginx

 (注意,这里配置了server_name为www.yii.com。需要同时配置host文件,把www.yii.com映射到127.0.0.1)

二. php安装yii

下载php包 配置环境变量

yii安装参考官网:https://www.yiiframework.com/doc/guide/2.0/zh-cn/start-installation

安装好后,启动yii服务测试是否正常:

php yii serve

 

 

修改php.ini支持fastCGI:

搜索“extension_dir”,找到: e;xtension_dir = "ext" 先去前面的分号再改为 extension_dir = "D:\php\ext"

搜索“date.timezone”,找到:;date.timezone = 先去前面的分号再改为 date.timezone = Asia/Shanghai

搜索“enable_dl”,找到:enable_dl = Off 改为 enable_dl = On

搜索“cgi.force_redirect” ;cgi.force_redirect = 1 先去前面的分号再改为 cgi.force_redirect = 0

搜索“fastcgi.impersonate”,找到: ;fastcgi.impersonate = 1 去掉前面的分号

搜索“cgi.rfc2616_headers”,找到:;cgi.rfc2616_headers = 0 先去前面的分号再改为 cgi.rfc2616_headers = 1

搜索“php_mysql”,找到:”extension=php_mysql.dll和extension=php_mysqli.dll  去掉前面的“;”extension=php_mysql.dll和extension=php_mysqli.dll   (支持MYSQL数据库)

 

三. 启动fastCGI服务

什么是fastCGI?它有什么用?可以参考另一篇文章:php中fastcgi和php-fpm是什么东西

打开cmd命令:

C:\Users\Administrator>D:/php/php-cgi.exe -b 127.0.0.1:9000 -c D:/php/php.ini

 

启动后,看似没反应,实际已在任务管理器增加了php-cgi进程:

 

保持cmd命令行不退出,访问www.yii.com,发现可以正常访问:

 

posted @ 2019-01-04 10:50  冒雨ing  阅读(875)  评论(0编辑  收藏  举报