首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫

CentOS 5.6 YUM 安裝 Nginx + PHP-FPM + eAccelerator + MySQL 完整實戰手冊

     編輯:MySQL 資料庫相關知識

記錄一次 CentOS 5.6 生產環境部署 LNMP(Linux + Nginx + MySQL + PHP)的完整流程,包含第三方源配置、套件安裝、Nginx 與 PHP-FPM 整合、權限問題排查、驗證測試,適合需在舊系統維護或重現舊環境的運維人員參考。

環境與前置決策

  • OS:CentOS 5.6(EOL,僅供歷史維護參考)
  • 安裝方式:YUM + 第三方源
  • 組件版本:Nginx、PHP 5.2.17(EOL)、PHP-FPM、eAccelerator、MySQL(系統自帶)
  • 不安裝 Apache,純 Nginx 架構
  • 安裝 GNOME 桌面便於圖形化管理

步驟 1:配置第三方 YUM 源

CentALT 源(Nginx、PHP 相關)


cat > /etc/yum.repos.d/alt.ru.repo << 'EOF'
[CentALT]
name=CentALT Packages for Enterprise Linux 5 - $basearch
baseurl=https://centos.alt.ru/repository/centos/5/$basearch/
enabled=1
gpgcheck=0
EOF

EPEL 源(依賴包)


# 64位
rpm -Uvh https://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
# 32位
rpm -Uvh https://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm

步驟 2:安裝套件


yum update
yum install nginx php-fpm php-cli php-pdo php-mysql php-mcrypt php-mbstring php-gd php-tidy php-xml php-xmlrpc php-pear php-eaccelerator

系統自動解析依賴,安裝 PHP 5.2.17 系列套件。

步驟 3:啟動服務


# 圖形界面:系統 → 管理 → 服務
# 或命令行
service nginx start
service php-fpm start
chkconfig nginx on
chkconfig php-fpm on

步驟 4:驗證 Nginx 靜態服務


# 默認根目錄 /usr/share/nginx/html
echo "nginx ok" > /usr/share/nginx/html/test.html
curl https://127.0.0.1/test.html
# 瀏覽器訪問 https://IP/ 見到 Nginx 歡迎頁

步驟 5:Nginx 整合 PHP-FPM(核心配置)

編輯 /etc/nginx/nginx.conf


# 找到並取消註釋以下區塊
location ~ \.php$ {
    root           /usr/share/nginx/html;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html$fastcgi_script_name;
    include        fastcgi_params;
}

關鍵修正:原配置 SCRIPT_FILENAME /scripts$fastcgi_script_name 路徑錯誤,導致 No input file specified。必須改為實際 Web 根目錄絕對路徑。

重載 Nginx


service nginx reload

步驟 6:驗證 PHP 執行


cat > /usr/share/nginx/html/phpinfo.php << 'EOF'

EOF

curl https://127.0.0.1/phpinfo.php
# 或瀏覽器訪問

常見錯誤與解決

現象 原因 解決
下載 PHP 文件而非執行 location ~ \.php$ 未生效 檢查 nginx.conf 語法、重載、路徑正確
No input file specified SCRIPT_FILENAME 路徑錯誤 改為 Web 根目錄絕對路徑
Access denied 目錄權限不足 chmod 755 /usr/share/nginx/html -R(生產建議 755 + 正確擁有者)
502 Bad Gateway php-fpm 未啟動或端口不匹配 service php-fpm status、檢查 fastcgi_pass 端口

步驟 7:驗證 eAccelerator 載入

在 phpinfo() 頁面搜尋 eAccelerator,確認版本、共享記憶體大小、快取命中率等信息顯示正常。

步驟 8:MySQL 驗證(系統自帶)


service mysqld start
chkconfig mysqld on
mysql -u root -p
# 建議執行 mysql_secure_installation 加固

生產環境補充建議(現代視角)

  • 棄用 CentOS 5 / PHP 5.2:均已 EOL,無安全更新,極高風險
  • 遷移建議:CentOS 7/8/Stream / Rocky Linux / AlmaLinux + PHP 8.1+ + PHP-FPM + Nginx 1.20+ + MySQL 8.0 / MariaDB 10.5+
  • eAccelerator → Opcache:PHP 5.5+ 內建 Opcache,性能更好、維護中
  • 配置管理:Ansible / SaltStack 自動化部署,版本控制所有配置
  • 監控:Prometheus + Node Exporter + Nginx Exporter + PHP-FPM Exporter + MySQL Exporter

本文記錄的是歷史版本部署流程,僅供遺留系統維護參考。新項目請務必選用現代、受支援的技術棧,安全與性能雙贏。

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