You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多
文档控制台
免费开始使用

Laravel 5.4项目php artisan命令失效,提示无法打开输入文件artisan求助

Troubleshooting "Could not open input file: artisan" in Laravel 5.4

Hey there, let's work through this issue step by step—since you already tried adding a downloaded artisan file and it didn't help, we need to dig into the specifics of Laravel 5.4's setup. Here's what to check next:

  1. Double-check your working directory
    It sounds obvious, but it's easy to accidentally navigate into a subfolder (like app/ or public/) where the artisan file doesn't live. Run pwd (Linux/macOS) or cd (Windows Command Prompt) to confirm you're in the root directory of your project—this is the folder that contains app/, vendor/, config/, and your newly added artisan file.

  2. Use the correct Laravel 5.4 artisan file
    The artisan file you downloaded from the master branch is for the latest Laravel versions, which have subtle differences from 5.4. Replace your current artisan file with the exact version for 5.4. Here's the correct content:

    #!/usr/bin/env php
    <?php
    
    define('LARAVEL_START', microtime(true));
    
    require __DIR__.'/vendor/autoload.php';
    
    $app = require_once __DIR__.'/bootstrap/app.php';
    
    $kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
    
    $status = $kernel->handle(
        $input = new Symfony\Component\Console\Input\ArgvInput,
        new Symfony\Component\Console\Output\ConsoleOutput
    );
    
    $kernel->terminate($input, $status);
    
    exit($status);
    
  3. Fix file permissions
    Make sure your artisan file has the right execution permissions. Run this command in your project root:

    chmod +x artisan
    

    Even if you use php artisan directly, ensuring the file is readable by your PHP process can prevent hidden access issues.

  4. Reinstall dependencies and refresh autoload
    Laravel's artisan relies heavily on the vendor/ directory and autoload files. If your vendor/ folder was corrupted or deleted (which might explain why artisan went missing in the first place), run these commands to restore it:

    composer install
    composer dump-autoload
    

    This will reinstall all required packages for Laravel 5.4 and regenerate the autoload mappings that artisan needs to run.

  5. Verify bootstrap files exist
    The artisan file loads bootstrap/app.php to initialize the Laravel application. If this file is missing or damaged, artisan will fail even if the main file exists. Check that bootstrap/app.php is present in your project—if it's gone, restore it from a backup or the Laravel 5.4 repository.

  6. Confirm PHP version compatibility
    Laravel 5.4 requires PHP 5.6.4 or higher. Run php -v in your terminal to make sure your current PHP version meets this requirement. Using an outdated PHP version can cause unexpected errors with framework files.

If you work through these steps, you should get your artisan commands working again. Let me know if any step hits a snag!

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

火山引擎 最新活动