php 文件的 500 内部服务器错误而不是 html
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17693391/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
500 Internal Server Error for php file not for html
提问by KarSho
My site having 4-5 static pages only. index.html& index.phpboth are there. index.html is working fine. If I change to index.php, it's giving 500 Internal Server Error
. I don't know where is my mistake?
我的网站只有 4-5 个静态页面。index.html和index.php都在那里。index.html 工作正常。如果我更改为 index.php,它会给出500 Internal Server Error
. 我不知道我的错误在哪里?
Note:If I use .htaccessfile with php_flag display_errors 1
,
注意:如果我使用.htaccess文件php_flag display_errors 1
,
It's showing Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
它显示 Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
If I use .htaccessfile with empty
,
如果我使用.htaccess文件empty
,
It's showing Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
它显示 Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
And if I give ../contact-us.php
, it's showing correctly.
如果我给../contact-us.php
,它显示正确。
Thanks...
谢谢...
回答by Hast
500 Internal Server Error is shown if your php code has fatal errors but error displaying is switched off. You may try this to see the error itself instead of 500 error page:
如果您的 php 代码有致命错误但错误显示已关闭,则会显示 500 Internal Server Error。你可以试试这个来查看错误本身而不是 500 错误页面:
In your php file:
在你的 php 文件中:
ini_set('display_errors', 1);
In .htaccess file:
在 .htaccess 文件中:
php_flag display_errors 1
回答by David Valenza
A PHP file must have permissions set to 644. Any folder containing PHP files and PHP access (to upload files, for example) must have permissions set to 755. PHP will run a 500 error when dealing with any file or folder that has permissions set to 777!
PHP 文件的权限必须设置为 644。任何包含 PHP 文件和 PHP 访问权限(例如上传文件)的文件夹都必须设置为 755。PHP 在处理任何设置了权限的文件或文件夹时将运行 500 错误到 777!
回答by Saran
It was changing the line endings (from Windows CRLF to Unix LF) in the .htaccess
file that fixed it for me.
它正在更改.htaccess
为我修复它的文件中的行尾(从 Windows CRLF 到 Unix LF)。
回答by Winter
I know this question is old, however I ran into this problem on Windows 8.1 while trying to use .htaccess files for rewriting. My solution was simple, I forgot to modify the following line in httpd.conf
我知道这个问题很老,但是我在尝试使用 .htaccess 文件进行重写时在 Windows 8.1 上遇到了这个问题。我的解决方案很简单,我忘记修改httpd.conf中的以下行
#LoadModule rewrite_module modules/mod_rewrite.so
to
到
LoadModule rewrite_module modules/mod_rewrite.so
Restarted the apache monitor, now all works well. Just posting this as an answer because someone in the future may run across the same issue with a simple fix.
重新启动 apache 监视器,现在一切正常。仅将此作为答案发布,因为将来有人可能会通过简单的修复遇到相同的问题。
Good luck!
祝你好运!
回答by TheRookierLearner
I was having this problem because I was trying to connect to MySQL but I didn't have the required package. I figured it out because of @Amadan's comment to check the error log. In my case, I was having the error: Call to undefined function mysql_connect()
我遇到这个问题是因为我试图连接到 MySQL,但我没有所需的包。我想通了是因为@Amadan 的评论来检查错误日志。就我而言,我遇到了错误:Call to undefined function mysql_connect()
If your PHP file has any code to connect with a My-SQL db then you might need to install php5-mysql
first. I was getting this error because I hadn't installed it. All my file permissions were good. In Ubuntu, you can install it by the following command:
如果您的 PHP 文件有任何代码可以与 MySQL 数据库连接,那么您可能需要先安装php5-mysql
。我收到这个错误是因为我没有安装它。我所有的文件权限都很好。在 Ubuntu 中,您可以通过以下命令安装它:
sudo apt-get install php5-mysql
sudo apt-get install php5-mysql
回答by Lin
Google guides me here but it didn't fix mine, this is a very general question and there are various causes, so I post my problem and solution here for reference in case anyone might read this later.
谷歌在这里指导我,但它没有解决我的问题,这是一个非常普遍的问题,有各种原因,所以我在这里发布我的问题和解决方案以供参考,以防任何人稍后阅读。
Another possible cause of 500 error is syntax error in header(...)
function, like this one:
500 错误的另一个可能原因是header(...)
函数中的语法错误,如下所示:
header($_SERVER['SERVER_PROTOCOL'] . '200 OK');
Be aware there should be space between server protocol and status code, so it should be:
请注意服务器协议和状态代码之间应该有空格,所以它应该是:
header($_SERVER['SERVER_PROTOCOL'] . ' 200 OK');
So I suggest check your http header call if you have it in your code.
因此,如果您的代码中有它,我建议检查您的 http 标头调用。