Httpd(apache)部署php日志报Invalid command 'php value'错误

来自三线的随记
Admin讨论 | 贡献2021年10月6日 (三) 15:28的版本

随记:

当部署 php + httpd(Apahe) 环境的时候,如果出现错误 /var/www/html/.htaccess: Invalid command 'php_value', perhaps misspelled or defined by a module not included in the server configuration

原因在于 httpd mpm模式为非prefork模式,而且在.htacess文件中使用了php_value指令设置php环境参数,apache mpm mode有三种,具体性能差异可以百度谷歌

解决手段:

  1. 不在.htaccess中使用php_value,使用其他指令或在php中设置相关参数
  2. 修改apache的mpm模式
  3. 谷歌

当前环境httpd mpm 模式可以通过命令httpd -V查询

Server version: Apache/2.4.37 (centos)
Server built:   May 20 2021 04:33:06
Server's Module Magic Number: 20120211:83
Server loaded:  APR 1.6.3, APR-UTIL 1.6.1
Compiled using: APR 1.6.3, APR-UTIL 1.6.1
Architecture:   64-bit
Server MPM:     event
  threaded:     yes (fixed thread count)
    forked:     yes (variable process count)
Server compiled with....
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_SYSVSEM_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=256
 -D HTTPD_ROOT="/etc/httpd"
 -D SUEXEC_BIN="/usr/sbin/suexec"
 -D DEFAULT_PIDLOG="run/httpd.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="conf/mime.types"
 -D SERVER_CONFIG_FILE="conf/httpd.conf"

默认为 event 模式

如果是通过dnf / yum之类的包管理工具安装的话,可以通过修改/etc/httpd/conf.modules.d/00-mpm.conf 文件修改mpm模式

[root@temp conf.modules.d]# cat 00-mpm.conf
# Select the MPM module which should be used by uncommenting exactly
# one of the following LoadModule lines.  See the httpd.conf(5) man
# page for more information on changing the MPM.

# prefork MPM: Implements a non-threaded, pre-forking web server
# See: http://httpd.apache.org/docs/2.4/mod/prefork.html
#
# NOTE: If enabling prefork, the httpd_graceful_shutdown SELinux
# boolean should be enabled, to allow graceful stop/shutdown.
#
LoadModule mpm_prefork_module modules/mod_mpm_prefork.so

# worker MPM: Multi-Processing Module implementing a hybrid
# multi-threaded multi-process web server
# See: http://httpd.apache.org/docs/2.4/mod/worker.html
#
#LoadModule mpm_worker_module modules/mod_mpm_worker.so

# event MPM: A variant of the worker MPM with the goal of consuming
# threads only for connections with active processing
# See: http://httpd.apache.org/docs/2.4/mod/event.html
#
#LoadModule mpm_event_module modules/mod_mpm_event.so


注释掉mod_mpm_event.so,取消注释mod_mpm_prefork.so 重启apache即可