Apache-2.4

如何為 mod-php 刪除 php-fpm

  • April 25, 2022

我們有一個執行非常緩慢的網站。我懷疑它是 php-fpm 配置,但如果不是問題,我不想玩它,我想先進行性能測試。

所以我複製了我們的負載均衡器生產虛擬機之一,並想刪除 php-fpm 但不確定如何刪除。

CentOS 7.6、httpd 2.4.38、php7.2

停止 php-fpm 顯然只會破壞它。移動文件 /etc/httpd/conf.d/php-fpm.conf 只會停止對 PHP 文件的所有解釋,那麼我如何將它恢復到 mod_php 呢?

編輯:1)已安裝mod_php72u.x86_64 2)添加了一個php.conf文件,/etc/httpd/conf.d/內容如下:

#
# The following lines prevent .user.ini files from being viewed by Web clients.
#
<Files ".user.ini">
   Require all denied
</Files>

#
# Allow php to handle Multiviews
#
AddType text/html .php

#
# Add index.php to the list of files that will be served as directory
# indexes.
#
DirectoryIndex index.php

# mod_php options
#
<IfModule  mod_php7.c>
   #
   # Cause the PHP interpreter to handle files with a .php extension.
   #
   <FilesMatch \.(php|phar)$>
       SetHandler application/x-httpd-php
   </FilesMatch>

   #
   # Uncomment the following lines to allow PHP to pretty-print .phps
   # files as PHP source code:
   #
   #<FilesMatch \.phps$>
   #    SetHandler application/x-httpd-php-source
   #</FilesMatch>

   #
   # Apache specific PHP configuration options
   # those can be override in each configured vhost
   #
   php_value session.save_handler "files"
   php_value session.save_path    "/var/lib/php/mod_php/session"
   php_value soap.wsdl_cache_dir  "/var/lib/php/mod_php/wsdlcache"

   #php_value opcache.file_cache   "/var/lib/php/mod_php/opcache"
</IfModule>

要回來,這很簡單:

  1. 解除安裝 php-fpm 或停止它:
sudo yum remove php72u-fpm.x86_64 php72u-fpm-httpd.noarch

或者

sudo systemctl stop php-fpm
  1. 再次安裝 mod_php
sudo yum install mod_php72u.x86_64
  1. 配置 httpd 將使用哪個監聽器。配置文件顯示必須使用 prefork/etc/httpd/conf.modules.d/15-php.conf包含以下內容:
# Cannot load both php5 and php7 modules
<IfModule !mod_php5.c>
 <IfModule prefork.c>
   LoadModule php7_module modules/libphp7.so
 </IfModule>
</IfModule>

/etc/httpd/conf.modules.d/00-mpm.conf註釋掉

#LoadModule mpm_event_module modules/mod_mpm_event.so

並打開LoadModule mpm_prefork_module modules/mod_mpm_prefork.so

  1. 重啟 Apache/httpd
sudo systemctl restart httpd

劇透警告:從簡短的測試來看,它不是 php-fpm,所以現在我必須弄清楚到底是什麼導致了緩慢。

引用自:https://serverfault.com/questions/962533