萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 程式設計 >  >> 網路程式設計 >> PHP 程式設計

Windows 下 Apache + PHP + ASP + JSP 多功能服務器搭建全記錄

軟件準備

  • Apache 2.2.4 (Win32) — 下載
  • JDK — 官網下載
  • PHP 4.x — 下載
  • InstantASP (iASP) — 關鍵組件,實現 ASP 支持
  • Resin 2.1.4 — 提供 JSP/Servlet 容器

Apache 安裝與基礎配置

  1. 雙擊安裝包,一路 Next。網絡域名、服務器域名、管理員郵箱可隨意填寫(個人用戶)。
  2. 強烈建議安裝至 C:\ 根目錄,避免後續配置路徑麻煩。
  3. 安裝完成後訪問 https://localhost/ 或 https://127.0.0.1 驗證,服務列表中可見 Apache。

httpd.conf 關鍵修改

  • DocumentRoot:指定網站根目錄,末尾不加斜槓。
  • DirectoryIndex:添加 index.php index.php3 index.php4 index.cgi index.pl index.asp,項目間以空格分隔。
  • Port:未裝 IIS 保持 80,否則改為 81 或修改 IIS 端口。
  • #BindAddress * → BindAddress 127.0.0.1。

PHP 4 安裝與整合

  1. 安裝至 C:\php4(勿更改路徑)。
  2. 將 msvcrt.dll 複製到 C:\WINNT\system32(提示覆蓋選是)。
  3. php.ini-dist 改名為 php.ini 複製至 C:\WINNT。
  4. 編輯 httpd.conf 追加:
    ScriptAlias /php4/ "C:/php4/"
    AddType application/x-httpd-php4 .php
    AddType application/x-httpd-php4 .php3
    AddType application/x-httpd-php4 .php4
    Action application/x-httpd-php4 "/php4/php.exe"
    DirectoryIndex index.php index.php3 index.php4
    
  5. 修改 php.ini:
    extension_dir = C:\php4
    extension=php_mysql.dll
    extension=php_gd2.dll
    extension=php_mbstring.dll
    ; 其他按需開啟
    
  6. 在 DocumentRoot 建立 test.php 驗證 。

InstantASP 整合 ASP 支持

  1. 關閉 Apache 服務。
  2. 默認安裝 iASP,安裝向導選擇 Instant ASP Native Servlet Support → Apache Server → 指定版本與 httpd.conf 路徑 → 自動配置。
  3. 測試 test.asp:<% Response.Write("Hello World!") %>。

Resin 整合 JSP/Servlet

  1. 解壓 Resin 至 C:\resin-ee-2.1.4。
  2. 以服務安裝:C:\resin-ee-2.1.4\bin\httpd.exe -install。
  3. 系統環境變量新增 resin_home=C:\resin-ee-2.1.4。
  4. 若已裝 JDK 無需額外配置,否則需設置 JAVA_HOME 與 PATH。
  5. 測試 .jsp 頁面驗證。

至此,單台 Windows 服務器同時支持 PHP、ASP、JSP,滿足多語言共存需求。生產環境請進一步優化安全、性能與監控配置。

copyright © 萬盛學電腦網 all rights reserved