windows本地配置php(yii)+nginx+fastcgi php中fastcgi和php-fpm是什麼東西
一. 配置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,發現可以正常訪問: