php5与mod_fcgid导致500错误 - 可能是错误的权限

时间:2012-09-11 11:18:10

标签: php permissions fastcgi mod-fcgid

每次我请求.php文件时,都会收到500错误代码。

我尝试了许多不同的文件权限并搜索了整个互联网(或者至少,感觉就像这样),但我找不到任何有用的东西。 (这不是一个容易找到suexec错误或类似的东西。但我想,这是权限的东西......可能我只是不知道/某一点...)

/var/log/apache2/error.log(LogLevel info)

[Tue Sep 11 12:47:21 2012] [info] Init: Seeding PRNG with 648 bytes of entropy
[Tue Sep 11 12:47:21 2012] [info] Init: Generating temporary RSA private keys (512/1024 bits)
[Tue Sep 11 12:47:21 2012] [info] Init: Generating temporary DH parameters (512/1024 bits)
[Tue Sep 11 12:47:21 2012] [info] Init: Initializing (virtual) servers for SSL
[Tue Sep 11 12:47:21 2012] [info] mod_ssl/2.2.16 compiled against Server: Apache/2.2.16, Library: OpenSSL/0.9.8o
[Tue Sep 11 12:47:21 2012] [notice] suEXEC mechanism enabled (wrapper: /usr/lib/apache2/suexec)
[Tue Sep 11 12:47:21 2012] [info] mod_fcgid: Process manager 30502 started
[Tue Sep 11 12:47:21 2012] [info] Init: Seeding PRNG with 648 bytes of entropy
[Tue Sep 11 12:47:21 2012] [info] Init: Generating temporary RSA private keys (512/1024 bits)
[Tue Sep 11 12:47:21 2012] [info] Init: Generating temporary DH parameters (512/1024 bits)
[Tue Sep 11 12:47:21 2012] [info] Shared memory session cache initialised
[Tue Sep 11 12:47:21 2012] [info] Init: Initializing (virtual) servers for SSL
[Tue Sep 11 12:47:21 2012] [info] mod_ssl/2.2.16 compiled against Server: Apache/2.2.16, Library: OpenSSL/0.9.8o
[Tue Sep 11 12:47:21 2012] [notice] Apache/2.2.16 (Debian) mod_fcgid/2.3.6 mod_ssl/2.2.16 OpenSSL/0.9.8o configured -- resuming normal operations
[Tue Sep 11 12:47:21 2012] [info] Server built: Apr  1 2012 06:40:08
[Tue Sep 11 12:48:08 2012] [info] mod_fcgid: server wiheha.us.to:/var/www/wiheha/conf.d/php.fcgi(30603) started
[Tue Sep 11 12:48:08 2012] [warn] [client 192.168.2.109] (104)Connection reset by peer: mod_fcgid: error reading data from FastCGI server
[Tue Sep 11 12:48:08 2012] [error] [client 192.168.2.109] Premature end of script headers: test.php
[Tue Sep 11 12:48:11 2012] [info] mod_fcgid: process /var/www/wiheha/conf.d/php.fcgi(30603) exit(communication error), terminated by calling exit(), return code: 255

我的设置是:Apache / 2.2.16(Debian)

文件结构:

drwxr-xr-x root   root    /var/
drwxr-xr-x root   root      www/
dr-xr-xr-x wiheha wiheha      wiheha/
dr-x------ wiheha wiheha        conf.d/
-r-x------ wiheha wiheha          php.fcgi
drwxr-xr-x wiheha wiheha        www/
-rw-r--r-- wiheha wiheha          favicon.ico
-rw-r--r-- wiheha wiheha          test.html
-rw-r--r-- wiheha wiheha          test.php

“wiheha”是用户btw:

wiheha:x:1005:1005::/var/www/wiheha:/bin/false
(adduser [...] --no-create-home --disabled-password --disabled-login [...])

/var/www/wiheha/conf.d/php.fcgi

#!/bin/sh
exec /usr/lib/cgi-bin/php

/var/www/wiheha/www/test.html

<!DOCTYPE html>
<html>
    (working, not much more than "lorem ipsum...")
</html>

/var/www/wiheha/www/test.php

<?php phpinfo(); ?>

的/ etc / apache2的/位点可用/ wiheha

<VirtualHost *:80>
    ServerName wiheha.us.to
    ServerAdmin michel.zimmer2@gmail.com
    DocumentRoot /var/www/wiheha/www
    SuexecUserGroup wiheha wiheha
    <Directory /var/www/wiheha/www/>
        AllowOverride All
        Options +ExecCGI
        AddHandler fcgid-script .php
        FCGIWrapper /var/www/wiheha/conf.d/php.fcgi .php
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

其他信息:

# cat /etc/debian_version
6.0.5
# apachectl -V
Server version: Apache/2.2.16 (Debian)
Server built:   Apr  1 2012 06:40:08
Server's Module Magic Number: 20051115:24
Server loaded:  APR 1.4.2, APR-Util 1.3.9
Compiled using: APR 1.4.2, APR-Util 1.3.9
Architecture:   32-bit
Server MPM:     Worker
  threaded:     yes (fixed thread count)
    forked:     yes (variable process count)
Server compiled with....
 -D APACHE_MPM_DIR="server/mpm/worker"
 -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 APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=128
 -D HTTPD_ROOT="/etc/apache2"
 -D SUEXEC_BIN="/usr/lib/apache2/suexec"
 -D DEFAULT_PIDLOG="/var/run/apache2.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="mime.types"
 -D SERVER_CONFIG_FILE="apache2.conf"
# /usr/lib/cgi-bin/php --version
PHP 5.3.3-7+squeeze14 with Suhosin-Patch (cgi-fcgi) (built: Aug  6 2012 20:08:51)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
    with Suhosin v0.9.32.1, Copyright (c) 2007-2010, by SektionEins GmbH

很长......我希望,这不是太多;-)

如果出现问题,请不要介意错误的语言 是的,您应该可以访问服务器:http://wiheha.us.to/

2 个答案:

答案 0 :(得分:5)

我(意外地)找到了解决方案: fcgi脚本(以及包含它的目录)必须至少是公开可执行的(r-x - x - x / 511)。

更新了文件结构:

drwxr-xr-x root   root    /var/
drwxr-xr-x root   root      www/
dr-xr-xr-x wiheha wiheha      wiheha/
dr-x--x--x wiheha wiheha        conf.d/
-r-x--x--x wiheha wiheha          php.fcgi
drwxr-xr-x wiheha wiheha        www/
-rw-r--r-- wiheha wiheha          favicon.ico
-rw-r--r-- wiheha wiheha          test.html
-rw-r--r-- wiheha wiheha          test.php

答案 1 :(得分:0)

同时检查以下内容:

http://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html

特殊PHP注意事项

默认情况下,PHP FastCGI进程在处理500个请求后退出,并且在此模块已连接到应用程序并发送下一个请求后,它们可能会退出。发生这种情况时,将记录一个错误,并将500内部服务器错误返回给客户端。可以通过将PHP_FCGI_MAX_REQUESTS设置为0来禁用此PHP行为,但如果PHP应用程序泄漏资源,则可能会出现问题。或者,可以将PHP_FCGI_MAX_REQUESTS设置为比默认值高得多的值,以降低此问题的频率。可以将FcgidMaxRequestsPerProcess设置为小于或等于PHP_FCGI_MAX_REQUESTS的值来解决问题。