Centos 7安裝php-fpm及使用mpm event

mpm要修改成event模式時,在預設狀況下修改apache的config 重啟apache會有錯誤

#LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
#LoadModule mpm_worker_module modules/mod_mpm_worker.so
LoadModule mpm_event_module modules/mod_mpm_event.so
Syntax error on line 31 of /etc/httpd/conf.d/php.conf: event

參考資料Apache的三种MPM模式比较:prefork,worker,event

ps.怎麼知道目前apache是什麼模式呢?可以輸入

httpd -V

Server MPM:event

httpd-V

為了解決這個問題,把php_value session部份設定為prefork時才使用或整個mark掉

php-conf
<IfModule mpm_prefork_module>
  php_value session.save_handler "files"
  php_value session.save_path    "/var/lib/php/session"
</IfModule>

再來需要安裝及使用fastCGI或php-fpm來處理php,如果安裝那php部份可能會直接顯示code出來,而不會進行轉譯

yum -y install php-fpm
nano /etc/httpd/conf.d/php.conf

修改

# line 5: change like follows
<FilesMatch \.php$>
#    SetHandler application/x-httpd-php
    SetHandler "proxy:fcgi://127.0.0.1:9000" 
</FilesMatch>

然後把php-fpm啟動及設成開機啟動

systemctl start php-fpm 
systemctl enable php-fpm 
systemctl restart httpd

參考資料CentOS 7 : Apache httpd : PHP + PHP-FPM : Server World

restart apache後就可以了

One thought to “Centos 7安裝php-fpm及使用mpm event”

  1. “Thank you so much for this guide! I was stuck on configuring Apache to use the event mode and kept running into the error with php.conf. Your solution with switching the session settings to prefork and using php-fpm worked perfectly. It really cleared up the issue I was facing. Also, I love how the instructions are detailed and easy to follow for someone like me who’s still learning the ropes of server management. By the way, if you’re working on other server configurations, I highly recommend checking out [Install Cockpit on Debian 12](https://docs.vultr.com/how-to-install-cockpit-on-debian-12). It helped me a lot too!”

發表迴響