這次教程主要以windows 2008 sp2 32bit standard配置PHP 7.0RC2+Nginx 1.9.4+Mysql 5.6.26,並且開啟HTTPS訪問。
一、準備工作
1、Nginx+php+mysql等下載並解壓:百度網盤
2、上述軟體可能用到的VC++運行庫下載:百度網盤
二、精簡併安裝Mysql
1、解壓mysql-5.6.26-win32.zip到D:\mysql-5.6.26-win32,並且重新命名my-default.ini為my.ini
2、刪除docs、include、mysql-test、scripts和sql-bench檔案夾,以及COPYING和README檔案,刪除剩餘檔案夾中pdb尾碼名的檔案
3、簡單配置下my.ini,修改如下:
# basedir = .....# datadir = .....修改為:basedir = "D:\mysql-5.6.26-win32"datadir = "D:\mysql-5.6.26-win32\data"
4、添加mysql服務
CMD命令如下:
D:\mysql-5.6.26-win32\bin>mysqld -install MySQL --defaults-file="D:\mysql-5.6.26-win32\my.ini"D:\mysql-5.6.26-win32\bin>net start MySQL 如果需要關閉服務,CMD命令輸入“net stop MySQL”(不用輸入雙引號)
如果需要卸載服務,CMD命令輸入“sc delete MySQL”(不用輸入雙引號)
二、安裝PHP
1、解壓php-7.0.0RC2-nts-Win32-VC14-x86.zip到D:\PHP並且重新命名php.ini-production為php.ini
2、修改php.ini
第725行 ; extension_dir = "ext" 先去前面的分號再改為 extension_dir = "D:\php\ext"
第735行enable_dl = Off 改為 enable_dl = On
第742行 ;cgi.force_redirect = 1 先去前面的分號再改為 cgi.force_redirect = 0
第770行 ;fastcgi.impersonate = 1 去掉前面的分號
第782行 ;cgi.rfc2616_headers = 0 先去前面的分號再改為 cgi.rfc2616_headers = 1
第879、883行,去掉前面的“;”extension=php_mysqli.dll和extension=php_pdo_mysql.dll (支援MYSQL資料庫)
3、可以去掉extension=前面的“;”開啟相應的擴充
三、安裝Nginx
1、解壓nginx-1.9.4到D:\nginx-1.9.4並且修改D:\nginx-1.9.4\conf\nginx.conf
2、修改nginx.conf如下:
修改65-71行 #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #}先將前面的“#”去掉,再把“/scripts”改為“$document_root”,這裡的“$document_root”就是指前面“root”所指的網站路徑,這是改完後的: location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
四、BAT一鍵運行
1、一鍵運行;解壓RunHiddenConsole到D,並把以下代碼儲存為start.bat
@echo offecho Starting PHP FastCGI...D:\RunHiddenConsole.exe D:\PHP\php-cgi.exe -b 127.0.0.1:9000 -c D:\PHP\php.iniecho Starting nginx...D:\RunHiddenConsole.exe D:\nginx-1.9.4\nginx.exe -p D:\nginx-1.9.4echo Starting mysql...
2、一件結束;把以下代碼儲存為stop.bat
@echo offecho Stopping nginx...taskkill /F /IM nginx.exe > nulecho Stopping PHP FastCGI...taskkill /F /IM php-cgi.exe > nulexit
3、phpinfo輸出資訊
五、開啟HTTPS訪問
1、SLL免費認證可以去沃通申請,沃通免費申請地址
2、我這邊申請好了,把for nginx.zip提取到D:\nginx-1.9.4\conf
3、修改D:\nginx-1.9.4\conf\nginx.conf檔案
修改98-115行:
#server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #}去掉每行前面的#,並且添加 location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
修改後完整如下:
server { listen 443 ssl; server_name localhost; ssl_certificate 1_www.myxzy.com_bundle.crt; ssl_certificate_key 2_www.myxzy.com.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; location / { root html; index index.php index.html index.htm; } location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
4、HTTPS下phpinfo輸出資訊(網域名稱本地host來測試)