PHP上传 - 500内部服务器错误 [英] PHP Upload - 500 Internal Server Error

查看:200
本文介绍了PHP上传 - 500内部服务器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上传大约8MB或更高的文件时,我收到500内部服务器错误。

When uploading files of around 8MB or over, I recieve a 500 Internal Server Error.


  1. php.ini 中的所有PHP设置都是正确的

  2. maxAllowedContentLength 已在web.config中设置

  1. All PHP settings in php.ini are correct
  2. maxAllowedContentLength has been set in the web.config



服务器信息



正如人们可以从 maxAllowedContentLength 中看到的那样,我运行 IIS 7.5 ,使用FastCGI和PHP 5.3.17

Server Info

As one can probably tell from the maxAllowedContentLength, I am running IIS 7.5, with FastCGI and PHP 5.3.17

为了实现这一目标,我尝试了很多不同的事情,但却找不到问题。

I have tried so many different things to get this working but simply cannot find the issue.

但是,我发现以下信息可能有助于找出问题的根源:

However, I have found the following bits of info that may help figure out the root of this problem:


  1. 当使用我在服务器上的Media Wiki上传文件(较大的文件)时,我收到相同的错误,这表明它在我的代码中不是错误。

  2. 最重要的是 - 我成功了在Plesk文件管理器中上传一个18MB的文件,这显然意味着Plesk能够解决这个配置问题。我试图将所有Plesk控制面板设置复制到IIS中的此域,但这似乎不起作用。

  3. 在脚本执行之前返回错误,因为我尝试在顶部写 exit; 以尝试获取空白屏幕,但这会被忽略并返回500错误。

  1. When uploading files (larger ones) using the Media Wiki that I have on the server, I receive the same error, this goes to show that it is not an error in my code.
  2. Most importantly - I managed to upload an 18MB file in the Plesk File Manager, this obviously means that Plesk was able to get around this config issue. I have tried to copy all of the Plesk Control Panel settings over to this domain in IIS but this does not seem to work.
  3. The error is being returned before the script is executed, as I have tried writing exit; at the top to try to get a blank screen, but this is ignored and the 500 error is returned.

我认为问题出在 configure命令部分PHP配置,因为当我更改 .php 文件的处理程序映射以使用Plesk php-cgi.exe时/ code>而不是通常的,我没有得到500内部错误。话虽如此,我不能把它放在这个PHP版本上,因为它是Plesk自己的 exe ,还有其他配置问题。

I think that the issue lies within the configure command part of the PHP configuration, because when I change the handler mapping of the .php files to use the Plesk php-cgi.exe instead of the usual one, I do not get the 500 Internal Error. Having said that, I cannot leave it on this PHP version as it is Plesk's own exe and there are other configuration issues.

我认为可能与configure命令有关的原因很简单,因为这与一个 phpinfo()之间存在很大差异。

The reason why I think it may be to do with the configure command, is simply because this differs hugely from one phpinfo() to the other.

如果您有任何想法或建议,请发布。我已经尝试了所有知识,似乎无法解决这个问题。如果只是Linux ...

If you have any ideas or suggestions, please post them. I have tried everything to my knowledge and cannot seem to fix this. If only it was Linux...

提前致谢

UPDATE 1

忘记添加,PHP错误日志中没有返回错误。至于IIS错误,我不知道在哪里看

Forgot to add, there are no errors being returned in the PHP error log. As for IIS errors, I do not know where to look

更新2

这是我放在 web.config 文件中的内容:

This is what I have placed in my web.config file:

<security>
    <requestFiltering>
        <requestLimits maxAllowedContentLength="2147483647" /> 
    </requestFiltering>
</security>

更新3

在您的帮助下,我们设法获得IIS显示的错误。这是我收到的:

With your help, we have managed to get the error displayed by IIS. This is what I am receiving:


PHP警告:POST内容长度12221448字节超过限制
的8388608字节第0行未知

PHP Warning: POST Content-Length of 12221448 bytes exceeds the limit of 8388608 bytes in Unknown on line 0

这与 post_max_size 有关吗?

更新4

PHP设置如下(来自 phpinfo( )):

PHP settings as follows (from phpinfo()):


post_max_size = 64M
memory_limit = 128M
max_file_uploads = 20
max_execution_time = 6000
upload_max_filesize = 64M


更新5

最后,为了防止任何人发现任何潜在问题,Plesk能够上传大文件绝对没问题,所以我假设他们的php-cgi.exe编译方式不同。当我读取其配置的phpinfo()时, configure命令信息非常不同:

Lastly, just in case anybody can spot any potential issues, Plesk is able to upload large files absolutely fine, so I assumed that their php-cgi.exe was compiled differently. When I read a phpinfo() of their configuration the configure command information was very different:

我的配置:


cscript / nologo configure.js--​​enable-snapshot-build
--disable-isapi - enable-debug-pack - without-mssql
--without-pdo-mssql - without-pi3web
--with-pdo-oci = C:\ php-sdk \ oracle \ instantclient10 \ sdk,共享
--with-oci8 = C:\ php-sdk \ oracle \ instantclient10 \ sdk,共享
--with-oci8-11g = C:\php-sdk \ oracle \ instantclient11 \ sdk,共享
--enable-object-out-dir = .. / obj / - -enable-com-dotnet = shared
--with-mcrypt = static - disable-static-analyze

cscript /nologo configure.js "--enable-snapshot-build" "--disable-isapi" "--enable-debug-pack" "--without-mssql" "--without-pdo-mssql" "--without-pi3web" "--with-pdo-oci=C:\php-sdk\oracle\instantclient10\sdk,shared" "--with-oci8=C:\php-sdk\oracle\instantclient10\sdk,shared" "--with-oci8-11g=C:\php-sdk\oracle\instantclient11\sdk,shared" "--enable-object-out-dir=../obj/" "--enable-com-dotnet=shared" "--with-mcrypt=static" "--disable-static-analyze"

Plesk的配置:


cscript / nologo configure.js--​​enable-debug-pack - enable-cli
--enable-cgi - enable-isapi - enable-one-shot - enable-pdo
--en able-intl - with-openssl = shared - with-pdo-odbc
--with-iconv - with-xml - with-xsl - with-mysql
--with-mysqlnd - with-mysqli - with-pdo-sqlite
--with-pdo-mysql - with-curl = shared--enable-mbstring
--enable-mbregex - with-imap = shared - enable-sockets
--enable-shmop - -enable-soap

cscript /nologo configure.js "--enable-debug-pack" "--enable-cli" "--enable-cgi" "--enable-isapi" "--enable-one-shot" "--enable-pdo" "--enable-intl" "--with-openssl=shared" "--with-pdo-odbc" "--with-iconv" "--with-xml" "--with-xsl" "--with-mysql" "--with-mysqlnd" "--with-mysqli" "--with-pdo-sqlite" "--with-pdo-mysql" "--with-curl=shared" "--enable-mbstring" "--enable-mbregex" "--with-imap=shared" "--enable-sockets" "--enable-shmop" "--enable-soap"

UPDATE(ANSWER)
这是非常奇怪的 phpinfo()信息说一件事,但显然被忽略了,不知道为什么。

UPDATE (ANSWER) This is extremely weird as the phpinfo() info is saying one thing, but it is obviously being ignored, not sure why.

如果我改变了Plesk中的 post_max_size ,针对该特定域/子域,然后没有任何更改(尽管它在 phpinfo()中似乎已更改)。但是,如果我实际更改了php.ini中的 post_max_value ,那么这就解决了这个问题。

If I change the post_max_size in Plesk, for that particular domain/sub-domain, then nothing is changed (although it appears to have changed in the phpinfo()). However, if I actually change the post_max_value in the php.ini then this fixes the issue.

之所以如此这不是解决这个问题的好方法,只是因为当Plesk更新时,php.ini会被覆盖,因为PHP会更新,结果对php.ini所做的更改就会丢失。这意味着每次Plesk更新时我都需要对php.ini进行更改。这就是为什么Plesk能够在不更改php.ini的情况下更改PHP设置的原因。

The reason why this is not a good way to fix this, is simply because when Plesk updates, the php.ini is overwritten as PHP is updated and resultantly the changes made to the php.ini are lost. Which means that everytime that Plesk updates I will need to make changes tot he php.ini. This is why Plesk offers the ability to change PHP settings without making changes to the php.ini.

任何人都可以想到为什么PHP忽略本地值并恢复到php.ini中的值,即使php.ini声明本地值不同?

Can anybody think of why PHP is ignoring the local value and reverting to the value in the php.ini, even though the php.ini states that the local value is different?

推荐答案

如果看一下 PHP的源代码,你可以看到文件 php-5.4.8-src\main\rfc1867.c 第706-709行:

If you look at the source code of PHP, you can see on the file php-5.4.8-src\main\rfc1867.c line 706-709 this:

if (SG(post_max_size) > 0 && SG(request_info).content_length > SG(post_max_size)) {
    sapi_module.sapi_error(E_WARNING, "POST Content-Length of %ld bytes exceeds the limit of %ld bytes", SG(request_info).content_length, SG(post_max_size));
    return;
}

同样存在于文件 php-5.4中。 8 src\main\SAPI.c
因此,消息 PHP警告:POST内容长度12221448字节超过第0行中未知的8388608字节的限制是关于post_max_size设置。您已使用phpinfo()确认已正确配置此设置,但它似乎仍使用默认值8M。

Same is there also in file php-5.4.8-src\main\SAPI.c. So, the message PHP Warning: POST Content-Length of 12221448 bytes exceeds the limit of 8388608 bytes in Unknown on line 0 is about post_max_size setting. You have confirmed from using phpinfo() that you have this setting configured correctly, but it seems to be using the default value of 8M anyway.

至于原因,请参阅< a href =https://stackoverflow.com/questions/11730198/php-post-max-size-local-value-overridden-by-master-value-on-plesk-iis>此主题:


事实证明,在Windows上,你只能设置
标记的ini指令 PHP_INI_USER 每个目录。不幸的是,
upload_max_filesize post_max_size 都是 PHP_INI_PERDIR
来自
的PHP文档 http://php.net /manual/en/configuration.changes.php

As it turns out, on Windows, you can only set ini directives that are marked PHP_INI_USER per directory. Unfortunately, upload_max_filesize and post_max_size are both PHP_INI_PERDIR. From the PHP docs at http://php.net/manual/en/configuration.changes.php


对于从此运行的任何脚本,该目录的设置都将处于活动状态目录或其任何子目录。密钥下的
值应该具有PHP配置指令
的名称和字符串值。不解析值中的PHP常量。
但是,只有PHP_INI_USER中可更改的配置值可以这样设置,PHP_INI_PERDIR值不能。

所以尽管Plesk有一个改变那些指令的界面,并且
即使 phpinfo()选择了它们,他们什么都不做更改
实际的最大上传大小。
Plesk不允许您更改Windows上的
,而 phpinfo()不应该报告这个改变,但
你能做什么。

So even though Plesk has an interface to change those directives, and even though phpinfo() picks up on them, they do nothing to change the actual max upload sizes. Plesk should not allow you to change those on Windows, and phpinfo() should not report the change, but what can you do.

所以,它是post_max_size,需要在php上设置。 INI。即使phpinfo另有说法,Plesk设置也无法正常工作。我还打开了关于phpinfo行为的错误输入,因为似乎没有是一个条目。

So, it's post_max_size, and it needs to be set on php.ini. Plesk setting simply will not work, even though phpinfo says otherwise. I also opened a bug entry on phpinfo behaviour as there didn't seem to be an entry for it.

这篇关于PHP上传 - 500内部服务器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆