如何使PHP显示错误,而不是给我500个内部服务器错误

发布于 2025-02-13 18:14:45 字数 172 浏览 0 评论 0 原文

这从未发生过。通常它会显示错误,但现在只会给我500个内部服务器错误。当然,当它显示错误时,它是不同的服务器。现在我在新服务器上(我有完整的根源,所以如果我需要在php.ini中的某个地方进行配置,我可以。

我只是通过将文件传输到另一台服务器并在那里运行以找到错误来忍受它,但这变得太乏味了。有办法解决这个问题吗?

This has never happened before. Usually it displays the error, but now it just gives me a 500 internal server error. Of course before, when it displayed the error, it was different servers. Now I'm on a new server (I have full root, so if I need to configure it somewhere in the php.ini, I can.) Or perhaps its something with Apache?

I've been putting up with it by just transferring the file to my other server and running it there to find the error, but that's become too tedious. Is there a way to fix this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

萤火眠眠 2025-02-20 18:14:46

检查 error_reporting display_errors display_startup_errors 在您的 php.ini 文件中的设置。它们应分别设置为 e_all ”(尽管您不应在生产服务器上使用 display_errors ,因此请禁用此问题并使用<代码> log_errors 而不是/何时部署)。您还可以在脚本的开头更改这些设置( Display_startup_errors )以在运行时设置它们(尽管您可能不会以这种方式捕获所有错误):

error_reporting(E_ALL);
ini_set('display_errors', 'On');

之后,重新启动服务器。

Check the error_reporting, display_errors and display_startup_errors settings in your php.ini file. They should be set to E_ALL and "On" respectively (though you should not use display_errors on a production server, so disable this and use log_errors instead if/when you deploy it). You can also change these settings (except display_startup_errors) at the very beginning of your script to set them at runtime (though you may not catch all errors this way):

error_reporting(E_ALL);
ini_set('display_errors', 'On');

After that, restart server.

谎言 2025-02-20 18:14:46

使用 php -l&lt; filename&gt; (这是'l')从命令行中输出可能导致php丢弃状态500错误的语法错误。它将输出之类的内容:

php解析错误:语法错误,意外'}'in&lt; fileName&gt;在第18行

Use php -l <filename> (that's an 'L') from the command line to output the syntax error that could be causing PHP to throw the status 500 error. It'll output something like:

PHP Parse error: syntax error, unexpected '}' in <filename> on line 18

我的鱼塘能养鲲 2025-02-20 18:14:46

值得注意的是,如果您的错误是由于.htaccess造成的,例如丢失的rewrite_module,您仍然会看到500个内部服务器错误。

It's worth noting that if your error is due to .htaccess, for example a missing rewrite_module, you'll still see the 500 internal server error.

相思碎 2025-02-20 18:14:46

请小心检查INI文件中其他地方是否

display_errors

处于

error_reporting

活动状态(不是评论)。

我的开发服务器拒绝在升级后显示错误
kubuntu 16.04-我多次检查了php.ini php.ini ...事实证明有一个diplay_errors = off;在我的下方约100行,

display_errors = on;

请记住最后一条!

Be careful to check if

display_errors

or

error_reporting

is active (not a comment) somewhere else in the ini file.

My development server refused to display errors after upgrade to
Kubuntu 16.04 - I had checked php.ini numerous times ... turned out that there was a diplay_errors = off; about 100 lines below my

display_errors = on;

So remember the last one counts!

你另情深 2025-02-20 18:14:46

尽量不要去

MAMP > conf > [your PHP version] > php.ini

,而是

MAMP > bin > php > [your PHP version] > conf > php.ini

在那里更改,它对我有用...

Try not to go

MAMP > conf > [your PHP version] > php.ini

but

MAMP > bin > php > [your PHP version] > conf > php.ini

and change it there, it worked for me...

伴梦长久 2025-02-20 18:14:46

启用从PHP代码显示的错误对我来说是不起作用的。就我而言,使用NGINX和PHP-FMP,我使用 grep 跟踪日志文件。例如,我知道文件名 mycode.php 导致错误500,但不知道哪一行。从控制台中,我使用此功能:

/var/log/php-fpm# cat www-error.log | grep mycode.php

我有输出:

[04-Apr-2016 06:58:27] PHP Parse error:  syntax error, unexpected ';' in /var/www/html/system/mycode.php on line 1458

这可以帮助我找到具有错字的线路。

Enabling error displaying from PHP code doesn't work out for me. In my case, using NGINX and PHP-FMP, I track the log file using grep. For instance, I know the file name mycode.php causes the error 500, but don't know which line. From the console, I use this:

/var/log/php-fpm# cat www-error.log | grep mycode.php

And I have the output:

[04-Apr-2016 06:58:27] PHP Parse error:  syntax error, unexpected ';' in /var/www/html/system/mycode.php on line 1458

This helps me find the line where I have the typo.

故人的歌 2025-02-20 18:14:46

如果所有其他方法都失败了,请尝试移动(即bash中)所有文件和目录“远方”,然后逐一添加它们。

我刚刚发现,我的.htaccess文件正在引用一个不存在的.htpasswd文件。 (#愚蠢的)

If all else fails try moving (i.e. in bash) all files and directories "away" and adding them back one by one.

I just found out that way that my .htaccess file was referencing a non-existant .htpasswd file. (#silly)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文