Windows下安裝Nginx+php+mysql環境
參考文章: https://www.cnblogs.com/anlia/p/5916758.html
系統:Windows 7 64位系統
安裝之前,首先下載軟體:
Nginx: http://nginx.org/en/download.html
PHP 7.3.3: http://php.net/downloads.php
mysql: 已提前安裝
1:在D盤建立資料夾Nginx+php+Mysql,路徑為:D:\Nginx+php+Mysql
2:安裝Nginx,安裝目錄為:D:\Nginx+php+Mysql\nginx-1.12.2
1.開啟D:\Nginx+php+Mysql\nginx-1.12.2目錄,執行該資料夾下的nginx.exe
2.測試是否啟動nginx。開啟瀏覽器訪問 http://localhost 或 http://127.0.0.1,看看是否出現“Welcome to nginx!”,出現的證明已經啟動成功了。
若啟動不成功,檢視是否埠被佔用。
3:安裝PHP,安裝目錄為:D:\Nginx+php+Mysql\php-7.3.3
4,安裝mySQL,安裝目錄為: 略
5:修改Nginx的conf檔案:
目錄為D:\Nginx+php+Mysql\nginx\conf
檔名為:nginx.conf
1. 去掉worker_processes前的#號,開啟一個程序
2. 新增events
3. 設定http->設定server->支援php
#usernobody; worker_processes 1; #error_loglogs/error.log; #error_loglogs/error.lognotice; #error_loglogs/error.loginfo; #pidlogs/nginx.pid; events { worker_connections 1024; } http { includemime.types; default_typeapplication/octet-stream; #log_formatmain '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_loglogs/access.logmain; sendfileon; #tcp_nopushon; #keepalive_timeout 0; keepalive_timeout 65; #gzipon; server { listen 80; server_namelocalhost; #charset koi8-r; #access_loglogs/host.access.logmain; location / { root d:/Nginx+php+Mysql/nginx/html; indexindex.html index.htm; } error_page 500 502 503 504/50x.html; location = /50x.html { roothtml; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { roothtml; fastcgi_pass 127.0.0.1:9000; fastcgi_indexindex.php; fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name; includefastcgi_params; } } }
4.測試nginx是否安裝成功

6:修改php下php.ini-development檔案,將檔名修改為php.ini,找開php.ini:
搜尋“extension_dir”,找到extension_dir = "ext" 先去前面的分號再改為 extension_dir = "./ext"
搜尋“php_mysql”,找到:”extension=php_mysql.dll和extension=php_mysqli.dll 去掉前面的“;”extension=php_mysql.dll和extension=php_mysqli.dll (支援MYSQL資料庫)
相對與PHP5,PHP7的最大變化之一是移除了mysql擴充套件,推薦使用mysqli或者pdo_mysql, 實際上在PHP5.5開始,PHP就著手開始準備棄用mysql擴充套件,如果你使用mysql擴充套件, 可能看到過這樣的提示”Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in”. 所以在以後的程式中,為了保持相容性,要儘量減少使用mysql擴充套件用於資料庫連線.
檢視php是否安裝成功:

7:在php目錄下新建檔案php-cgi.vbs,用php-cgi.vbs檔案啟動php-cgi:
開啟php-cgi.vbs,寫入啟動編碼:
set wscriptObj = CreateObject("Wscript.Shell") wscriptObj.run "php-cgi -b 127.0.0.1:9000",0
8:在D:\Nginx+php+Mysql目錄下新建啟動項:runServer.bat和停止項stopServer.bat
在啟動項runServer.bat中輸入:
@echo off echo Starting nginx... cd %~dp0nginx start "" "./nginx.exe" echo Starting mysql... net start mysql echo Starting PHP FastCGI... cd %~dp0PHP start "" "php-cgi.vbs" pause Exit
在停止項中輸入:
@echo off echo Stopping nginx... taskkill /F /IM nginx.exe > nul echo Stopping PHP FastCGI... taskkill /F /IM php-cgi.exe > nul echo Stopping mysql... net stop mysql pause exit
9:最後,檢視是否啟動成功:
在nginx的html目錄下D:\Nginx+php+Mysql\nginx\html,新建phpinfo.php
寫入:
<?php phpinfo(); ?>
在瀏覽器中輸入phpinfo.php的路徑,檢視是否配置成功:( http://localhost/phpinfo.php )

1. 更改php.ini 首先php.ini的配置中把 ;cgi.fix_pathinfo=0 改為 cgi.fix_pathinfo=1 ※這裡預設都是註釋掉的,預設值就是1 2. 在nginx/conf/nginx.conf 找到: fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; 改為: fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; ※其實這在標題5中有修改,是我沒注意
修改配置之後搞定:
