You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel执行make:command命令返回Content-type: text/html异常求助

解决Laravel artisan命令执行异常仅返回Content-type: text/html的问题
  • 回到项目根目录执行命令:你当前处于route目录,而artisan文件在Laravel项目的根目录下,必须切换到根目录才能正常执行命令。执行cd ..逐步返回上级目录,直到执行ls能看到artisan文件,再重新运行:

    php artisan make:command CheckPendingOrders
    
  • 检查PHP版本与文件权限:

    • 执行php -v确认PHP版本匹配当前Laravel项目的要求(比如Laravel 9要求PHP 8.0及以上),版本不兼容会导致命令执行失败。
    • 若artisan文件没有执行权限,执行chmod +x artisan赋予可执行权限。
  • 排查HTTP头输出异常原因:
    出现Content-type: text/html通常是因为项目全局文件(如配置文件、bootstrap脚本)意外输出了内容,导致CLI模式下PHP触发HTTP头输出。可以先执行php artisan list测试基础命令,如果同样出现该输出,需要检查:

    • bootstrap/app.php、config目录下的所有文件,是否存在echo、print、var_dump等输出语句,或者文件开头/结尾有多余的空格、换行。
    • 尝试用php -n artisan make:command CheckPendingOrders执行命令(不加载php.ini配置),排查是否是PHP配置中的自动加载脚本导致的问题。
  • 手动创建命令(应急方案):
    如果以上方法都无效,可以手动创建命令文件:

    1. 在app/Console/Commands目录下新建CheckPendingOrders.php,内容如下:
      <?php
      
      namespace App\Console\Commands;
      
      use Illuminate\Console\Command;
      
      class CheckPendingOrders extends Command
      {
          protected $signature = 'orders:check-pending';
          protected $description = '检查待处理订单';
      
          public function handle()
          {
              // 编写你的命令逻辑
              $this->info('正在检查待处理订单...');
          }
      }
      
    2. 打开app/Console/Kernel.php,在$commands数组中添加:
      protected $commands = [
          \App\Console\Commands\CheckPendingOrders::class,
      ];
      

    之后执行php artisan list就能看到新增的命令。

内容的提问来源于stack exchange,提问作者Caleb

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 14:35:59