Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> 電腦軟體教學 >> 伺服器技術 >> 關於伺服器

Linux 下為已編譯 PHP 安裝 cURL 擴展(不重新編譯 PHP)

編輯:關於伺服器

當 PHP 已編譯安裝後,若需新增擴展(如 cURL),除重新完整編譯 PHP 外,更高效的方式是單獨編譯擴展模組並以 .so 動態載入。以下以 cURL 為例說明操作步驟:

1. 編譯安裝 cURL 庫

# 下載 cURL 原始碼(注意版本相容性,PHP 4.4.4 建議用 cURL 7.14)
./configure
make
# 注意:編譯後庫檔案在 lib/.libs/,需複製到 lib/
cp lib/.libs/libcurl.a lib/
# 確認 include/ 下有 easy.h、curl.h,lib/ 下有 libcurl.a

2. 編譯 PHP cURL 擴展模組

cd php源碼目錄/ext/curl
phpize
./configure --with-curl=/path/to/curl安裝目錄
make
# 生成 modules/curl.so

3. 部署與啟用

# 複製到 PHP 擴展目錄
cp modules/curl.so /usr/local/php/lib/php/extensions/

# 修改 php.ini
extension=curl.so

# 重啟 Web 伺服器 (Apache/IIS/php-fpm)

關鍵提示: cURL 版本需與 PHP 版本相容;--with-curl 指向的目錄必須包含 include/ 與 lib/ 且庫檔案就緒。

Copyright © Windows教程網 All Rights Reserved