前言:Zend Guard 現狀與替代方案
Zend Guard (現屬 Perforce) 曾是 PHP 原始碼加密標準工具,但官方已於 2016 年停止更新,最新支援 PHP 5.6。PHP 7/8 專案請改用:
本文僅供維護舊版 PHP 5.3~5.6 專案參考。
Zend Guard 5.5 安裝與授權 (Windows)
- 下載
ZendGuard-5.5.0-Windows.exe 安裝。
- 授權檔:需
zend_guard.zl 授權檔 (試用版 14 天)。
- 系統時間技巧 (僅測試用):
- 安裝/授權時將系統時間調至 2010 年前。
- 編碼專案時將系統時間調至未來 (如 2099 年) 延長加密檔有效期。
- Help → Register → Search for license file → 選取
.zl。
專案編碼流程 (GUI)
- File → New → Zend Guard Project。
- 專案名、輸出目錄 (建議獨立資料夾)。
- Add File / Add Folder 選擇欲加密檔案 (可排除設定檔、圖片等)。
- 選擇 PHP 版本:必須與目標伺服器 PHP 版本完全一致 (如 5.3.10),否則執行會報錯。
- Finish → 右鍵專案 → Encode Project。
核心坑點:Zend Guard Loader 部署與 TS/NTS 陷阱
錯誤現象
Zend Guard Run-time support missing!
One or more files on this web site were encoded by Zend Guard and the required run-time support is not installed or properly configured.
原因分析
加密後的檔案需 Zend Guard Loader (免費擴充套件) 解碼執行。關鍵在於 PHP 編譯模式:
- TS (Thread Safe):Apache mod_php、IIS ISAPI 使用,
phpinfo() 顯示 Thread Safety => enabled。
- NTS (Non Thread Safe):PHP-FPM、CLI、CGI 使用,
Thread Safety => disabled。
Zend Guard Loader 官方僅提供 NTS 版本 DLL/so。若伺服器跑 TS 版 PHP,無法直接使用 Loader。
解決方案
| 情況 | 方案 |
| Windows + Apache (TS) | 改用 NTS 版 PHP + FastCGI (mod_fcgid) 或改用 IIS FastCGI |
| Linux + Apache (TS) | 改用 PHP-FPM (NTS) + Apache mod_proxy_fcgi |
| 已是 NTS (PHP-FPM/CLI) | 直接下載對應版本 Loader 即可 |
Loader 安裝步驟 (Linux NTS 範例)
# 1. 確認 PHP 版本與 API 版本
php -v
# PHP 5.3.29 (cli) (built: ...)
# Zend Engine v2.3.0 ... Zend Extension Build => API220090626,NTS
# 2. 下載對應 Loader (API220090626, NTS)
wget https://downloads.zend.com/guard/5.5.0/ZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gz
tar xzf ZendGuardLoader-*.tar.gz
cp ZendGuardLoader-*/php-5.3.x/ZendGuardLoader.so /usr/lib/php/extensions/
# 3. 修改 php.ini
cat >> /etc/php/5.3/php.ini <<'EOF'
[Zend Guard Loader]
zend_extension=/usr/lib/php/extensions/ZendGuardLoader.so
zend_loader.enable=1
zend_loader.disable_licensing=1
zend_loader.obfuscation_level_support=3
zend_loader.license_path=
EOF
# 4. 重啟 PHP-FPM
systemctl restart php5.3-fpm
# 5. 驗證
php -m | grep -i zend
php -r "echo 'Zend Guard Loader: ' . (extension_loaded('Zend Guard Loader') ? 'OK' : 'MISSING');"
Windows 部署細節 (WampServer 範例)
; php.ini 追加 (路徑依實際調整)
[Zend Guard Loader]
zend_extension="D:/wamp/bin/php/php5.3.10/ext/ZendLoader.dll"
zend_loader.enable=1
zend_loader.disable_licensing=1
zend_loader.obfuscation_level_support=3
zend_loader.license_path=
必須使用 NTS 版 PHP:WampServer 預設提供 TS 版,需自行下載 php-5.3.10-nts-Win32-VC9-x86.zip 替換。
常見錯誤對照表
| 錯誤訊息 | 原因 | 解決 |
| Zend Guard Run-time support missing | Loader 未安裝或版本不符 | 對照 PHP API 版本與 TS/NTS 安裝 Loader |
| Encoded file has expired | 編碼時系統時間導致授權過期 | 重新編碼,確保編碼機時間正確或設為遠未來 |
| Cannot decode file | PHP 版本與編碼時選擇的版本不符 | 重新編碼並選擇正確目標 PHP 版本 |
| Fatal error: Unable to initialize module | Zend Extension API 版本衝突 | Loader 必須與 PHP 核心 API 版本完全一致 (如 API220090626) |
遷移建議:從 Zend Guard 到 ionCube
- 購買 ionCube Encoder 授權 (支援 PHP 8.3)。
- 重新編碼專案 (ionCube 介面相似,支援命令列批次)。
- 目標伺服器安裝
ioncube_loader (提供 TS/NTS/ARM 全版本)。
- 測試通過後逐步替換部署。
完整遷移腳本與 Docker 測試環境見 GitHub。
- 上一篇文章: PHP 偵測用戶代理與匿名等級:從 HTTP 標頭到實戰防刷指南
- 下一篇文章: PHP 動態呼叫與物件導向:變數函數、呼叫器模式與安全防禦全解析
Copyright ©
程式碼之家 All Rights Reserved