1. 程式人生 > 資料庫 >Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

準備篇

一、環境說明:

作業系統:Windows Server 2019

PHP版本:php 7.3.11

MySQL版本:MySQL 8.0.18.0

二、相關軟體下載:

1、PHP下載地址:

https://windows.php.net/downloads/releases/php-7.3.11-nts-Win32-VC15-x64.zip

2、MySQL下載地址:

https://cdn.mysql.com//Downloads/MySQLInstaller/mysql-installer-community-8.0.18.0.msi

3、Visual C++ Redistributable for Visual Studio 2015(安裝PHP、MySQL需要此外掛)

https://download.visualstudio.microsoft.com/download/pr/11100229/78c1e864d806e36f6035d80a0e80399e/VC_redist.x86.exe

https://download.visualstudio.microsoft.com/download/pr/11100230/15ccb3f02745c7b206ad10373cbca89b/VC_redist.x64.exe

4、Microsoft URL 重寫模組 2.0下載地址(IIS偽靜態需要此外掛)

https://download.microsoft.com/download/4/E/7/4E7ECE9A-DF55-4F90-A354-B497072BDE0A/rewrite_x64_zh-CN.msi

安裝篇

一、安裝IIS10.0

控制面板-系統和安全-管理工具

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

伺服器管理器

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

新增角色和功能

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

下一步

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

選擇:基於角色或基於功能的安裝

下一步

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

選擇:從伺服器池中選擇伺服器

下一步

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

選擇:Web伺服器(IIS)

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

新增功能

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

下一步

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

下一步

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

下一步

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

確保CGI被選中,其他的角色服務根據需要選擇,如果不知道如何選擇,建議選擇全部功能。

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

下一步

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

安裝

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

顯示安裝成功,點關閉。

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

可以看到角色和伺服器組中已經有了IIS

開啟IE瀏覽器,輸入http://127.0.0.1/會看到下面的介面

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

IIS10.0已經安裝完成。

二、安裝PHP

1、Visual C++ Redistributable for Visual Studio 2017 (x86、x64)

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

安裝x86

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

安裝x64

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

全部安裝完成後,點關閉。

2、安裝php-7.3.11-nts-Win32-VC15-x64.zip

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

解壓php-7.3.11-nts-Win32-VC15-x64.zip檔案

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

重新命名資料夾為php73,把php73資料夾拷貝到C盤根目錄

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

開啟C:\php

複製php.ini-production為php.ini

用記事本開啟php.ini

做如下新增修改:

extension_dir = "C:\php73\ext" #設定php模組路徑

date.timezone = PRC #設定時區為中國時區

cgi.force_redirect = 0 #開啟以CGI方式執行php

fastcgi.impersonate = 1;

cgi.rfc2616_headers = 1

以下php擴充套件模組,根據需要選擇開啟,取消前面的分號為開始相應擴充套件模組

extension=curl

extension=gd2

extension=mbstring

extension=exif

extension=mysqli

extension=sockets

extension=php_xmlrpc

extension=php_pdo_mysql

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

修改完成後,儲存退出

3、配置IIS支援PHP

開啟控制面板-系統和安全-管理工具

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

開啟伺服器管理器

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

雙擊左邊“起始頁”下面的計算機名稱

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

找到中間的IIS部分,開啟“處理程式對映”。

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

點右邊的“新增模組對映”

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

請求路徑:*.php

模組:FastCgiModule

可執行檔案(可選):C:\php73\php-cgi.exe

名稱:FastCGI

最後,確定

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

雙擊左邊“起始頁”下面的計算機名稱

找到中間的IIS部分,開啟“FastCGI設定”

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

右鍵選中:C:\php73\php-cgi.exe然後選擇編輯

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

監視對檔案所做的更改:C:\php73\php.ini

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

環境變數,點旁邊的"..."

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

點“新增”

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

Name:PHP_FCGI_MAX_REQUESTS

Value:1000

確定

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

雙擊左邊“起始頁”下面的計算機名稱

找到中間的IIS部分,開啟“預設文件”

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

點右邊的“新增”

名稱:index.php

確定

可以選擇右邊操作下面“上移”選項,把index.php移到最上邊

4、測試php程式是否正常執行

開啟:

C:\inetpub\wwwroot

新建一個index.php檔案

內容如下:

<?php

phpinfo();

?>

最後,儲存退出

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

在瀏覽器裡面開啟http://127.0.0.1/

出現下面的介面,說php程式可以正常執行。

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

三、安裝MySQL

雙擊開啟mysql-installer-community-8.0.18.0

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

選中“Custom”(自定義安裝)

Next

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

Edit

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

選擇MySQL Servers 64位

Filter

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

點開MySQL Servers

選擇要安裝的版本,點箭頭移動到右邊視窗

Next

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

Execute

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

Next

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

Next

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

預設,Next

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

Config Type(配置型別):

Developer Machine(開發伺服器)

Server Machine(普通伺服器)

Dedicated Machine(專用伺服器)

這裡選擇第二項:Server Machine(普通伺服器)

勾選“TCP/IP ”

Port Number(埠):3306

勾選“Open firewall port for network access“(開啟防火牆埠網路訪問)

Next

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

選擇第二項,使用相容MySQL5.7之前版本的加密方式

Next

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

MySQL Root password:輸入密碼

Repeat Password:重複輸入密碼

設定好之後,點Next

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

勾選:配置MySQL系統服務

Windows Server Name(Windows服務名):MySQL80

勾選:“Start the MySQL Server at System Startup“(在系統啟動時啟動MySQL伺服器)

勾選:Standard System Account 預設使用系統使用者執行

Next

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

Execute

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

Finish

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

Next

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

Finish

開啟MySQL安裝路徑

C:\Program Files\MySQL\MySQL Server 8.0

新建配置檔案my.ini

[mysqld]

# 設定3306埠

port=3306

# 設定mysql的安裝目錄

basedir=C:\Program Files\MySQL\MySQL Server 8.0

# 設定mysql資料庫的資料的存放目錄

datadir=C:\Program Files\MySQL\Data

# 允許最大連線數

max_connections=1000

# 允許連線失敗的次數。這是為了防止有人從該主機試圖攻擊資料庫系統

max_connect_errors=10

# 服務端使用的字符集預設為UTF8

character-set-server=utf8

# 建立新表時將使用的預設儲存引擎

default-storage-engine=INNODB

# 預設使用“mysql_native_password”外掛認證

default_authentication_plugin=mysql_native_password

[mysql]

# 設定mysql客戶端預設字符集

default-character-set=utf8

[client]

# 設定mysql客戶端連線服務端時預設使用的埠

port=3306

default-character-set=utf8

儲存

開啟C:\ProgramData\Microsoft\Windows\Start Menu\Programs\MySQL\MySQL Server 8.0

雙擊MySQL Server 8.0 Command Line Client

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

輸入安裝時候的MySQL root賬號密碼,回車,登入到MySQL控制檯

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

MySQL安裝完成

四、配置IIS10.0支援偽靜態

雙擊安裝Microsoft URL 重寫模組rewrite_x64_zh-CN.msi

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

出現錯誤提示,確定

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

搜尋-執行

輸入regedit,確定,開啟登錄檔,找到:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W3SVC\Parameters

右側的MajorVersion是DWORD值,它的值十進位制是10,把它改成9。

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\InetStp

也是MajorVersion 項,這個也是dword值10(注意是十進位制),把它改成9

然後再次安裝,切記安裝完之後再改回來。

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

再次安裝

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

安裝

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

完成

Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程

在:控制面板-系統和安全-管理工具-Internet Information Services (IIS)管理器中可以看到”URL重寫“

在:網站根目錄下新建檔案web.config,新增偽靜態規則程式碼即可實現網站靜態化。

至此,Windows Server 2019 IIS10.0+PHP(FastCGI)+MySQL環境搭建教程完成。