Apache 2.0 引入 MPM 模組化架構,Red Hat 衍生版預設採用 prefork 以求穩定。本文記錄切換至 worker 的實際操作步驟與風險提醒。
# 1. 進入二進制目錄
cd /usr/sbin
# 2. 備份 prefork 執行檔
mv httpd httpd.prefork
# 3. 替換為 worker 執行檔
mv httpd.worker httpd
# 4. 修改 MPM 參數
vi /etc/httpd/conf/httpd.conf
# 找到 <IfModule worker.c> 區塊調整:
# StartServers 2
# MaxClients 150
# MinSpareThreads 25
# MaxSpareThreads 75
# ThreadsPerChild 25
# MaxRequestsPerChild 0
# 5. 重啟服務
/etc/init.d/httpd restart
# httpd -V | grep MPM
Server MPM: Worker
Apache is running a threaded MPM, but your PHP Module is not compiled to be threadsafe. You need to recompile PHP. Pre-configuration failed!
vi /etc/httpd/conf.d/php.conf
# 註解掉 LoadModule 行
# LoadModule php5_module modules/libphp5.so
但這會導致 PHP 完全失效,**不建議生產環境如此操作**。
若需高併發低記憶體,建議改用 Nginx + PHP-FPM 架構,而非強行切換 Apache worker。