{"id":22755,"date":"2024-11-21T13:07:05","date_gmt":"2024-11-21T05:07:05","guid":{"rendered":"https:\/\/fwq.ai\/blog\/22755\/"},"modified":"2024-11-21T13:07:05","modified_gmt":"2024-11-21T05:07:05","slug":"laravel-500%e9%94%99%e8%af%af-%e6%80%8e%e4%b9%88%e6%98%be%e7%a4%ba%e9%94%99%e8%af%af%e5%bc%82%e5%b8%b8","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/22755\/","title":{"rendered":"laravel 500\u9519\u8bef \u600e\u4e48\u663e\u793a\u9519\u8bef\u5f02\u5e38"},"content":{"rendered":"<p>laravel\u662f\u4e00\u6b3e\u975e\u5e38\u6d41\u884c\u7684php\u6846\u67b6\uff0c\u5b83\u88ab\u5e7f\u6cdb\u5e94\u7528\u4e8eweb\u5e94\u7528\u7a0b\u5e8f\u7684\u5f00\u53d1\u4e2d\u3002laravel\u6846\u67b6\u63d0\u4f9b\u4e86\u4e00\u79cd\u7b80\u5355\u6613\u7528\u7684\u65b9\u5f0f\u6765\u521b\u5efa\u548c\u7ba1\u7406web\u5e94\u7528\u7a0b\u5e8f\uff0c\u4f7f\u5f97php\u7684\u5f00\u53d1\u5de5\u4f5c\u53d8\u5f97\u66f4\u52a0\u9ad8\u6548\u3001\u8f7b\u677e\u548c\u6109\u5feb\u3002\u7136\u800c\uff0c\u4efb\u4f55\u6846\u67b6\u90fd\u4f1a\u51fa\u73b0\u4e00\u4e9b\u9519\u8bef\u548c\u5f02\u5e38\uff0c\u548claravel\u6846\u67b6\u4e5f\u4e0d\u4f8b\u5916\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u5728laravel\u6846\u67b6\u4e2d\u663e\u793a500\u9519\u8bef\u5f02\u5e38\u3002<\/p>\n<ol>\n<li>\u786e\u8ba4\u9519\u8bef\u62a5\u544a\u662f\u5426\u542f\u7528<\/li>\n<\/ol>\n<p>Laravel\u6846\u67b6\u6709\u4e2a\u7279\u70b9\uff0c\u5c31\u662f\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u4f1a\u9690\u85cf\u6240\u6709\u7684\u9519\u8bef\u62a5\u544a\u4fe1\u606f\uff0c\u4ee5\u4fdd\u62a4\u5e94\u7528\u7a0b\u5e8f\u7684\u9690\u79c1\u548c\u5b89\u5168\u6027\u3002\u56e0\u6b64\uff0c\u5982\u679c\u8981\u67e5\u770b500\u9519\u8bef\u7684\u8be6\u7ec6\u4fe1\u606f\uff0c\u9700\u8981\u786e\u8ba4\u4e00\u4e0bLaravel\u6846\u67b6\u662f\u5426\u542f\u7528\u4e86\u9519\u8bef\u62a5\u544a\u3002\u6253\u5f00\u914d\u7f6e\u6587\u4ef6config\/app.php\uff0c\u5728\u8be5\u6587\u4ef6\u4e2d\u627e\u5230debug\u914d\u7f6e\u9879\uff0c\u786e\u4fdd\u5176\u503c\u4e3atrue\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre> 'debug' =&amp;gt; env('APP_DEBUG', true),<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5982\u679c\u8be5\u914d\u7f6e\u9879\u7684\u503c\u4e3afalse\uff0c\u5219\u9700\u8981\u5c06\u5176\u6539\u4e3atrue\uff0c\u8868\u793a\u5f00\u542f\u9519\u8bef\u62a5\u544a\u3002<\/p>\n<ol>\n<li>\u67e5\u770b\u9519\u8bef\u62a5\u544a\u65e5\u5fd7<\/li>\n<\/ol>\n<p>\u5982\u679cLaravel\u6846\u67b6\u542f\u7528\u4e86\u9519\u8bef\u62a5\u544a\uff0c\u4f46\u9875\u9762\u4e0a\u4ecd\u7136\u6ca1\u6709\u663e\u793a\u9519\u8bef\u5f02\u5e38\u4fe1\u606f\uff0c\u90a3\u4e48\u53ef\u4ee5\u67e5\u770bLaravel\u6846\u67b6\u7684\u9519\u8bef\u62a5\u544a\u65e5\u5fd7\u6587\u4ef6storage\/logs\/laravel.log\u3002\u8be5\u65e5\u5fd7\u6587\u4ef6\u8bb0\u5f55\u4e86\u6846\u67b6\u7684\u6240\u6709\u9519\u8bef\u4fe1\u606f\uff0c\u5305\u62ec500\u9519\u8bef\u5f02\u5e38\u3002<\/p>\n<p>\u53ef\u4ee5\u6253\u5f00\u8be5\u65e5\u5fd7\u6587\u4ef6\uff0c\u67e5\u770b\u6700\u65b0\u7684\u65e5\u5fd7\u4fe1\u606f\uff0c\u5b9a\u4f4d\u5230\u76f8\u5173\u7684\u9519\u8bef\u62a5\u544a\u4fe1\u606f\u3002\u6bd4\u5982\uff0c\u5982\u679c\u9047\u5230\u4e86\u201cMethodNotAllowedHttpException\u201d\u7684\u5f02\u5e38\u9519\u8bef\uff0c\u53ef\u4ee5\u5728\u65e5\u5fd7\u6587\u4ef6\u4e2d\u641c\u7d22\u8fd9\u4e2a\u5173\u952e\u5b57\uff0c\u67e5\u627e\u8be5\u5f02\u5e38\u7684\u8be6\u7ec6\u4fe1\u606f\u3002<\/p>\n<pre>[2021-10-01 14:27:59] local.ERROR: MethodNotAllowedHttpException in file \/var\/www\/html\/laravel-app\/vendor\/laravel\/framework\/src\/Illuminate\/Routing\/RouteCollection.php on line 255 {\"exception\":\"[object] (SymfonyComponentHttpKernelExceptionMethodNotAllowedHttpException(code: 0):...<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ol>\n<li>\u663e\u793a\u9519\u8bef\u8c03\u8bd5\u9875\u9762<\/li>\n<\/ol>\n<p>\u5982\u679c\u4ee5\u4e0a\u65b9\u6cd5\u90fd\u65e0\u6cd5\u89e3\u51b3\u95ee\u9898\uff0c\u53ef\u4ee5\u5728Laravel\u6846\u67b6\u4e2d\u663e\u793a\u9519\u8bef\u8c03\u8bd5\u9875\u9762\uff0c\u83b7\u53d6\u66f4\u591a\u7684\u9519\u8bef\u4fe1\u606f\u3002\u5177\u4f53\u64cd\u4f5c\u5982\u4e0b\uff1a<\/p>\n<p>\u5f00\u542flaravel-debugbar\uff08\u5b89\u88c5debugbar\uff1acomposer require barryvdh\/laravel-debugbar &#8211;dev\uff0c\u7136\u540e\u5728config\/app.php\u4e2d\u6dfb\u52a0ServiceProvider\uff09\uff1a<\/p>\n<pre>'providers' =&amp;gt; [\n\n    IlluminateValidationValidationServiceProvider::class,\n\n    IlluminateViewViewServiceProvider::class,\n\n    \/\/\u6dfb\u52a0\u8c03\u8bd5\u9762\u677f\u670d\u52a1\u63d0\u4f9b\u8005\u7c7b\n\n    BarryvdhDebugbarServiceProvider::class,\n\n],<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5728.env\u6587\u4ef6\u4e2d\u8bbe\u7f6eAPP_DEBUG=true\u3002<\/p>\n<p>\u5728app\/Exceptions\/Handler.php\u7684report\u65b9\u6cd5\u4e2d\u6dfb\u52a0\uff1a<\/p>\n<pre>if ($this-&amp;gt;shouldReport($exception)) {\n\n    \/\/\u5f00\u542f\u8c03\u8bd5\u9762\u677f\n\n    app('debugbar')-&amp;gt;enable();\n\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u7136\u540e\u8bbf\u95ee\u5e94\u7528\u7a0b\u5e8f\uff0c\u5c31\u80fd\u770b\u5230\u8be6\u7ec6\u7684\u9519\u8bef\u4fe1\u606f\u9875\u9762\u4e86\u3002\u5982\u679c\u4f7f\u7528\u7684\u662f\u672c\u5730\u5f00\u53d1\u73af\u5883\uff0c\u9519\u8bef\u4fe1\u606f\u9875\u9762\u5c06\u4f1a\u5305\u542b\u6240\u6709\u7684\u8c03\u8bd5\u4fe1\u606f\uff0c\u5305\u62ec\u5806\u6808\u8ddf\u8e2a\u3001\u8bf7\u6c42\u548c\u54cd\u5e94\u4fe1\u606f\u3001SQL\u67e5\u8be2\u65e5\u5fd7\u7b49\u3002<\/p>\n<ol>\n<li>\u603b\u7ed3<\/li>\n<\/ol>\n<p>\u5728\u5f00\u53d1Web\u5e94\u7528\u7a0b\u5e8f\u7684\u8fc7\u7a0b\u4e2d\uff0c500\u9519\u8bef\u662f\u4e00\u79cd\u5e38\u89c1\u7684\u5f02\u5e38\uff0c\u4f46\u5728Laravel\u6846\u67b6\u4e2d\u5c06\u5176\u8bca\u65ad\u5e76\u4fee\u590d\u5374\u5e76\u4e0d\u56f0\u96be\u3002\u901a\u8fc7\u672c\u6587\u63d0\u4f9b\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u6253\u5f00\u9519\u8bef\u62a5\u544a\u3001\u67e5\u770b\u9519\u8bef\u65e5\u5fd7\u548c\u5f00\u542f\u9519\u8bef\u8c03\u8bd5\u9875\u9762\u7b49\u65b9\u5f0f\u6765\u5b9a\u4f4d\u548c\u4fee\u590d\u95ee\u9898\u3002\u5f53\u7136\uff0c\u4e00\u65e6\u95ee\u9898\u5f97\u5230\u89e3\u51b3\uff0c\u4e5f\u5e94\u8be5\u5c06\u9519\u8bef\u62a5\u544a\u5173\u95ed\uff0c\u4ee5\u4fdd\u8bc1\u5e94\u7528\u7a0b\u5e8f\u7684\u5b89\u5168\u6027\u548c\u9690\u79c1\u6027\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662flaravel 500\u9519\u8bef \u600e\u4e48\u663e\u793a\u9519\u8bef\u5f02\u5e38\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>laravel\u662f\u4e00\u6b3e\u975e\u5e38\u6d41\u884c\u7684php\u6846\u67b6\uff0c\u5b83\u88ab\u5e7f\u6cdb\u5e94\u7528\u4e8eweb\u5e94\u7528\u7a0b\u5e8f\u7684\u5f00\u53d1\u4e2d\u3002laravel\u6846\u67b6\u63d0\u4f9b\u4e86\u4e00\u79cd\u7b80\u5355\u6613\u7528\u7684\u65b9\u5f0f\u6765\u521b\u5efa\u548c\u7ba1\u7406web\u5e94\u7528\u7a0b\u5e8f\uff0c\u4f7f\u5f97php\u7684\u5f00\u53d1\u5de5\u4f5c\u53d8\u5f97\u66f4\u52a0\u9ad8\u6548\u3001\u8f7b\u677e\u548c\u6109\u5feb\u3002\u7136\u800c\uff0c\u4efb\u4f55\u6846\u67b6\u90fd\u4f1a\u51fa\u73b0\u4e00\u4e9b\u9519\u8bef\u548c\u5f02\u5e38\uff0c\u548claravel\u6846\u67b6\u4e5f\u4e0d\u4f8b\u5916\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u5728laravel\u6846\u67b6\u4e2d\u663e\u793a500\u9519\u8bef\u5f02\u5e38\u3002 \u786e\u8ba4\u9519\u8bef\u62a5\u544a\u662f\u5426\u542f\u7528 Laravel\u6846\u67b6\u6709\u4e2a\u7279\u70b9\uff0c\u5c31\u662f\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u4f1a\u9690\u85cf\u6240\u6709\u7684\u9519\u8bef\u62a5\u544a\u4fe1\u606f\uff0c\u4ee5\u4fdd\u62a4\u5e94\u7528\u7a0b\u5e8f\u7684\u9690\u79c1\u548c\u5b89\u5168\u6027\u3002\u56e0\u6b64\uff0c\u5982\u679c\u8981\u67e5\u770b500\u9519\u8bef\u7684\u8be6\u7ec6\u4fe1\u606f\uff0c\u9700\u8981\u786e\u8ba4\u4e00\u4e0bLaravel\u6846\u67b6\u662f\u5426\u542f\u7528\u4e86\u9519\u8bef\u62a5\u544a\u3002\u6253\u5f00\u914d\u7f6e\u6587\u4ef6config\/app.php\uff0c\u5728\u8be5\u6587\u4ef6\u4e2d\u627e\u5230debug\u914d\u7f6e\u9879\uff0c\u786e\u4fdd\u5176\u503c\u4e3atrue\uff0c\u5982\u4e0b\u6240\u793a\uff1a &#8216;debug&#8217; =&amp;gt; env(&#8216;APP_DEBUG&#8217;, true), \u767b\u5f55\u540e\u590d\u5236 \u5982\u679c\u8be5\u914d\u7f6e\u9879\u7684\u503c\u4e3afalse\uff0c\u5219\u9700\u8981\u5c06\u5176\u6539\u4e3atrue\uff0c\u8868\u793a\u5f00\u542f\u9519\u8bef\u62a5\u544a\u3002 \u67e5\u770b\u9519\u8bef\u62a5\u544a\u65e5\u5fd7 \u5982\u679cLaravel\u6846\u67b6\u542f\u7528\u4e86\u9519\u8bef\u62a5\u544a\uff0c\u4f46\u9875\u9762\u4e0a\u4ecd\u7136\u6ca1\u6709\u663e\u793a\u9519\u8bef\u5f02\u5e38\u4fe1\u606f\uff0c\u90a3\u4e48\u53ef\u4ee5\u67e5\u770bLaravel\u6846\u67b6\u7684\u9519\u8bef\u62a5\u544a\u65e5\u5fd7\u6587\u4ef6storage\/logs\/laravel.log\u3002\u8be5\u65e5\u5fd7\u6587\u4ef6\u8bb0\u5f55\u4e86\u6846\u67b6\u7684\u6240\u6709\u9519\u8bef\u4fe1\u606f\uff0c\u5305\u62ec500\u9519\u8bef\u5f02\u5e38\u3002 \u53ef\u4ee5\u6253\u5f00\u8be5\u65e5\u5fd7\u6587\u4ef6\uff0c\u67e5\u770b\u6700\u65b0\u7684\u65e5\u5fd7\u4fe1\u606f\uff0c\u5b9a\u4f4d\u5230\u76f8\u5173\u7684\u9519\u8bef\u62a5\u544a\u4fe1\u606f\u3002\u6bd4\u5982\uff0c\u5982\u679c\u9047\u5230\u4e86\u201cMethodNotAllowedHttpException\u201d\u7684\u5f02\u5e38\u9519\u8bef\uff0c\u53ef\u4ee5\u5728\u65e5\u5fd7\u6587\u4ef6\u4e2d\u641c\u7d22\u8fd9\u4e2a\u5173\u952e\u5b57\uff0c\u67e5\u627e\u8be5\u5f02\u5e38\u7684\u8be6\u7ec6\u4fe1\u606f\u3002 [2021-10-01 14:27:59] local.ERROR: MethodNotAllowedHttpException in file \/var\/www\/html\/laravel-app\/vendor\/laravel\/framework\/src\/Illuminate\/Routing\/RouteCollection.php on line 255 {&#8220;exception&#8221;:&#8221;[object] (SymfonyComponentHttpKernelExceptionMethodNotAllowedHttpException(code: 0):&#8230; \u767b\u5f55\u540e\u590d\u5236 \u663e\u793a\u9519\u8bef\u8c03\u8bd5\u9875\u9762 \u5982\u679c\u4ee5\u4e0a\u65b9\u6cd5\u90fd\u65e0\u6cd5\u89e3\u51b3\u95ee\u9898\uff0c\u53ef\u4ee5\u5728Laravel\u6846\u67b6\u4e2d\u663e\u793a\u9519\u8bef\u8c03\u8bd5\u9875\u9762\uff0c\u83b7\u53d6\u66f4\u591a\u7684\u9519\u8bef\u4fe1\u606f\u3002\u5177\u4f53\u64cd\u4f5c\u5982\u4e0b\uff1a \u5f00\u542flaravel-debugbar\uff08\u5b89\u88c5debugbar\uff1acomposer require barryvdh\/laravel-debugbar &#8211;dev\uff0c\u7136\u540e\u5728config\/app.php\u4e2d\u6dfb\u52a0ServiceProvider\uff09\uff1a &#8216;providers&#8217; =&amp;gt; [ IlluminateValidationValidationServiceProvider::class, IlluminateViewViewServiceProvider::class, \/\/\u6dfb\u52a0\u8c03\u8bd5\u9762\u677f\u670d\u52a1\u63d0\u4f9b\u8005\u7c7b BarryvdhDebugbarServiceProvider::class, ], \u767b\u5f55\u540e\u590d\u5236 \u5728.env\u6587\u4ef6\u4e2d\u8bbe\u7f6eAPP_DEBUG=true\u3002 \u5728app\/Exceptions\/Handler.php\u7684report\u65b9\u6cd5\u4e2d\u6dfb\u52a0\uff1a if ($this-&amp;gt;shouldReport($exception)) { \/\/\u5f00\u542f\u8c03\u8bd5\u9762\u677f app(&#8216;debugbar&#8217;)-&amp;gt;enable(); } \u767b\u5f55\u540e\u590d\u5236 \u7136\u540e\u8bbf\u95ee\u5e94\u7528\u7a0b\u5e8f\uff0c\u5c31\u80fd\u770b\u5230\u8be6\u7ec6\u7684\u9519\u8bef\u4fe1\u606f\u9875\u9762\u4e86\u3002\u5982\u679c\u4f7f\u7528\u7684\u662f\u672c\u5730\u5f00\u53d1\u73af\u5883\uff0c\u9519\u8bef\u4fe1\u606f\u9875\u9762\u5c06\u4f1a\u5305\u542b\u6240\u6709\u7684\u8c03\u8bd5\u4fe1\u606f\uff0c\u5305\u62ec\u5806\u6808\u8ddf\u8e2a\u3001\u8bf7\u6c42\u548c\u54cd\u5e94\u4fe1\u606f\u3001SQL\u67e5\u8be2\u65e5\u5fd7\u7b49\u3002 \u603b\u7ed3 \u5728\u5f00\u53d1Web\u5e94\u7528\u7a0b\u5e8f\u7684\u8fc7\u7a0b\u4e2d\uff0c500\u9519\u8bef\u662f\u4e00\u79cd\u5e38\u89c1\u7684\u5f02\u5e38\uff0c\u4f46\u5728Laravel\u6846\u67b6\u4e2d\u5c06\u5176\u8bca\u65ad\u5e76\u4fee\u590d\u5374\u5e76\u4e0d\u56f0\u96be\u3002\u901a\u8fc7\u672c\u6587\u63d0\u4f9b\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u6253\u5f00\u9519\u8bef\u62a5\u544a\u3001\u67e5\u770b\u9519\u8bef\u65e5\u5fd7\u548c\u5f00\u542f\u9519\u8bef\u8c03\u8bd5\u9875\u9762\u7b49\u65b9\u5f0f\u6765\u5b9a\u4f4d\u548c\u4fee\u590d\u95ee\u9898\u3002\u5f53\u7136\uff0c\u4e00\u65e6\u95ee\u9898\u5f97\u5230\u89e3\u51b3\uff0c\u4e5f\u5e94\u8be5\u5c06\u9519\u8bef\u62a5\u544a\u5173\u95ed\uff0c\u4ee5\u4fdd\u8bc1\u5e94\u7528\u7a0b\u5e8f\u7684\u5b89\u5168\u6027\u548c\u9690\u79c1\u6027\u3002 \u4ee5\u4e0a\u5c31\u662flaravel 500\u9519\u8bef [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-22755","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/22755","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=22755"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/22755\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=22755"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=22755"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=22755"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}