手机端下拉列表
400-002-9968
安全类
服务器管理面板
应用系统
首页 > 在线帮助 >PHP FastCGI 模式运行出错:Premature end of script headers

PHP FastCGI 模式运行出错:Premature end of script headers

更新时间: 2022-06-14 10:27:50

适用版本:
Plesk Onyx for Linux
Plesk 12.5 for Linux
Plesk 12.0 for Linux
Plesk 11.x for Linux

问题
1. 将PHP模式切换为FastCGI时,一个secondary PHP 运行出错:
# tailf /var/www/vhosts/domain.tld/logs/error_log
(104)Connection reset by peer: mod_fcgid: error reading data from FastCGI server
Premature end of script headers: index.php

或出现下面的错误:
[fcgid:warn] [pid 1175:tid 140298957072128] (104)Connection reset by peer: [client xx.xx.xx.xx:50320] mod_fcgid: error reading data from FastCGI server
[core:error] [pid 1175:tid 140298957072128] [client xx.xx.xx.xx:50320] End of script output before headers: index.php
[fcgid:warn] [pid 1174:tid 140298982250240] (104)Connection reset by peer: [client xx.xx.xx.xx:50324] mod_fcgid: error reading data from FastCG

2. Apache日志显示内存错误
# less /etc/httpd/logs/error_log
Apache/2.2.15 (Unix) DAV/2 mod_fcgid/2.3.7 mod_python/3.3.1 Python/2.6.6 mod_ssl/2.2.15 OpenSSL/1.0.0-fips SVN/1.6.11 mod_perl/2.0.4 Perl/v5.10.1 configured -- resuming normal operations
[Errno 12] Cannot allocate memory

3. 系统日志显示suhosin警告
# less /var/log/syslog
hosting suhosin[32242]: ALERT - zend_mm_head corrupted at 0x2e02420 (attacker '203.0.113.2', file '/var/www/vhosts/example.com/httpdocs/index.php')

4. Suexec日志显示下面的错误:
# tailf /var/log/httpd/suexec_log
uid: (10033/ftpuser) gid: (504/504) cmd: cgi_wrapper
unknown error in docroot check (10033)

原因
1. PHP未使用FastCGI进行编译。
2. 服务器上没有足够的内存。
3. 域名php.ini被自定义过,含有错字,或有无效的配置。
4. /etc/passwd 文件的权限不正确。
5. 某个 php 模块不兼容。

解决方案
1. 使用SSH连接服务器,确保使用FastCGIPHP进行编译。可以使用下面的命令检查是否已启用fastcgi模块。
# /usr/local/psa/admin/bin/php_handlers_control --list
id:  display name:  version:    type:                                     cgi-bin:                php.ini:
fastcgi-5.2.17         5.2.17    5.2.17      cgi  /usr/local/php5.2.17/bin/php-cgi  /usr/local/lib/php.ini

检查PHP版本:
# /usr/local/php5.2.17-cgi/bin/php-cgi -v
PHP 5.2.17 (cgi) (built: Mar 27 2014 20:28:44)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies

如上所示,使用的是5.2.17 (cgi)。也就是说PHP只在CGI模式下运行。能够同时在CGIFastCGI模式下运行PHP如下:
# php-cgi -v
PHP 5.3.3 (cgi-fcgi) (built: Jul 12 2013 20:34:01)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
    with the ionCube PHP Loader v4.2.2, Copyright (c) 2002-2012, by ionCube Ltd.

如果未使用FastCGI模式编译过PHP,请使用选项 --enable-fastcgi 重新编译自定义 php

2. 请使用下面的命令确保服务器上有足够的内存:
# free -m

如果服务器是一个虚拟的容器,则可以使用下面的命令检查资源限制:
# cat /proc/user_beancounters

3. 域名php.ini可能已被手动自定义过或包含某个错误。例如:将php.ini中的兆字节设置成了128MB而不是128M
备份原始的域名php.ini然后重新配置域名:
 # mv /var/www/vhosts/system/example.com/etc/php.ini /var/www/vhosts/system/example.com/etc/php.ini_orig

 # /usr/local/psa/admin/bin/httpdmng --reconfigure-vhost --vhost-name=example.com

对于Plesk 11.5和更高版本,请使用下面的命令:
 # /usr/local/psa/admin/bin/httpdmng --reconfigure-domain --domain-name=example.com

4. 请确保 /etc/passwd 文件有如下的权限:
# ls -la /etc/passwd
-rw-r--r-- 1 root root 7643 Mar  3 12:54 /etc/passwd

微信扫码沟通
微信扫码沟通

微信扫码沟通

售前咨询
合作
售后
return head