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

Ubuntu 編譯安裝 PHP-FPM 5.2 完整實戰記錄

編輯:關於伺服器

版本與相依套件

  • PHP 5.2.10 + php-fpm 0.5.13 patch
  • Ubuntu 建議版本:10.04 LTS / 12.04 LTS(較新版本需調整套件名稱)

編譯前準備

# 下載原始碼與 patch
wget https://php-fpm.org/downloads/php-5.2.10-fpm-0.5.13.diff.gz
wget https://museum.php.net/php5/php-5.2.10.tar.bz2

# 安裝建置依賴
apt-get update
apt-get install build-essential libxml2-dev libmcrypt-dev libssl-dev \
  libldap2-dev libmhash-dev libmysqlclient15-dev libcurl4-openssl-dev \
  libpng12-dev libjpeg-dev libsasl2-dev

套用 Patch 與編譯

tar jxf php-5.2.10.tar.bz2
cd php-5.2.10
gunzip -c ../php-5.2.10-fpm-0.5.13.diff.gz | patch -p1

./configure \
  --prefix=/opt/php \
  --with-iconv --with-zlib --enable-xml --disable-rpath \
  --enable-discard-path --enable-safe-mode --enable-bcmath \
  --enable-shmop --enable-sysvsem --enable-inline-optimization \
  --with-curl --with-curlwrappers --enable-mbregex \
  --enable-fastcgi --enable-fpm --enable-force-cgi-redirect \
  --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf \
  --with-openssl --with-mhash --enable-pcntl --enable-sockets \
  --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip \
  --enable-soap --without-pear --with-mysql --with-mysqli \
  --enable-sqlite-utf8 --with-pdo-mysql --enable-ftp \
  --with-jpeg-dir --with-freetype-dir --with-png-dir

make && make install

後續配置與啟動

# 複製預設 php.ini
cp php.ini-dist /opt/php/lib/php.ini

# 建立服務腳本連結
ln -s /opt/php/sbin/php-fpm /etc/init.d/php-fpm
update-rc.d -f php-fpm defaults

# 啟動服務
/etc/init.d/php-fpm start

php-fpm.conf 關鍵優化參數

vi /opt/php/etc/php-fpm.conf

# 1. 開啟錯誤顯示(開發環境)
display_errors = 1

# 2. 設定郵件發送路徑
sendmail_path = /usr/sbin/sendmail -t -i

# 3. 指定執行使用者/群組(安全性)
user = www-data
group = www-data

# 4. 最大子進程數(依記憶體調整,建議 50-200)
max_children = 50

# 5. 請求處理超時
request_terminate_timeout = 60s

# 6. 慢日誌(排查效能瓶頸)
slowlog = /var/log/php-fpm-slow.log
request_slowlog_timeout = 10s

⚠️ 重要提醒

PHP 5.2 已於 2011 年停止維護,極不建議用於新專案。現代專案請直接使用 Ubuntu 官方倉庫的 PHP 7.4/8.x 系列:
apt-get install php-fpm php-mysql php-gd php-curl php-mbstring php-xml php-zip

適用場景

  • 維護極舊版專案無法升級時的緊急部署
  • 教學/研究歷史版本行為
  • 相容性測試環境
Copyright © Windows教程網 All Rights Reserved