首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> 網頁程式設計 >> PHP 程式設計 >> PHP 相關知識

Zend Guard 5.5 加密 PHP 專案實戰:安裝、授權、編碼與 Loader 部署完整指南

     編輯:PHP 相關知識

前言:Zend Guard 現狀與替代方案

Zend Guard (現屬 Perforce) 曾是 PHP 原始碼加密標準工具,但官方已於 2016 年停止更新,最新支援 PHP 5.6。PHP 7/8 專案請改用:

  • ionCube Encoder:商業、支援 PHP 8.3、效能佳、廣泛相容。
  • PHPCipher / SourceGuardian:商業替代方案。
  • 開源混淆:PHP Obfuscator、laganut/PHP-Obfuscator (僅混淆,非加密)。

本文僅供維護舊版 PHP 5.3~5.6 專案參考。

Zend Guard 5.5 安裝與授權 (Windows)

  1. 下載 ZendGuard-5.5.0-Windows.exe 安裝。
  2. 授權檔:需 zend_guard.zl 授權檔 (試用版 14 天)。
  3. 系統時間技巧 (僅測試用):
    • 安裝/授權時將系統時間調至 2010 年前。
    • 編碼專案時將系統時間調至未來 (如 2099 年) 延長加密檔有效期。
  4. Help → Register → Search for license file → 選取 .zl。

專案編碼流程 (GUI)

  1. File → New → Zend Guard Project。
  2. 專案名、輸出目錄 (建議獨立資料夾)。
  3. Add File / Add Folder 選擇欲加密檔案 (可排除設定檔、圖片等)。
  4. 選擇 PHP 版本:必須與目標伺服器 PHP 版本完全一致 (如 5.3.10),否則執行會報錯。
  5. 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。

解決方案

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 替換。

常見錯誤對照表

情況方案
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 即可
錯誤訊息原因解決
Zend Guard Run-time support missingLoader 未安裝或版本不符對照 PHP API 版本與 TS/NTS 安裝 Loader
Encoded file has expired編碼時系統時間導致授權過期重新編碼,確保編碼機時間正確或設為遠未來
Cannot decode filePHP 版本與編碼時選擇的版本不符重新編碼並選擇正確目標 PHP 版本
Fatal error: Unable to initialize moduleZend Extension API 版本衝突Loader 必須與 PHP 核心 API 版本完全一致 (如 API220090626)

遷移建議:從 Zend Guard 到 ionCube

  1. 購買 ionCube Encoder 授權 (支援 PHP 8.3)。
  2. 重新編碼專案 (ionCube 介面相似,支援命令列批次)。
  3. 目標伺服器安裝 ioncube_loader (提供 TS/NTS/ARM 全版本)。
  4. 測試通過後逐步替換部署。

完整遷移腳本與 Docker 測試環境見 GitHub。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved