这从未发生过。通常它会显示错误,但现在只会给我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?
发布评论
评论(7)
检查
error_reporting
,display_errors
和display_startup_errors
在您的php.ini
文件中的设置。它们应分别设置为e_all
和“
”(尽管您不应在生产服务器上使用display_errors
,因此请禁用此问题并使用<代码> log_errors 而不是/何时部署)。您还可以在脚本的开头更改这些设置(Display_startup_errors
)以在运行时设置它们(尽管您可能不会以这种方式捕获所有错误):之后,重新启动服务器。
Check the
error_reporting
,display_errors
anddisplay_startup_errors
settings in yourphp.ini
file. They should be set toE_ALL
and"On"
respectively (though you should not usedisplay_errors
on a production server, so disable this and uselog_errors
instead if/when you deploy it). You can also change these settings (exceptdisplay_startup_errors
) at the very beginning of your script to set them at runtime (though you may not catch all errors this way):After that, restart server.
使用
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
值得注意的是,如果您的错误是由于.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.
请小心检查INI文件中其他地方是否
处于
活动状态(不是评论)。
我的开发服务器拒绝在升级后显示错误
kubuntu 16.04-我多次检查了php.ini php.ini ...事实证明有一个diplay_errors = off;在我的下方约100行,
请记住最后一条!
Be careful to check if
or
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
So remember the last one counts!
尽量不要去
,而是
在那里更改,它对我有用...
Try not to go
but
and change it there, it worked for me...
启用从PHP代码显示的错误对我来说是不起作用的。就我而言,使用NGINX和PHP-FMP,我使用 grep 跟踪日志文件。例如,我知道文件名 mycode.php 导致错误500,但不知道哪一行。从控制台中,我使用此功能:
我有输出:
这可以帮助我找到具有错字的线路。
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:
And I have the output:
This helps me find the line where I have the typo.
如果所有其他方法都失败了,请尝试移动(即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)