The Misconception About Installing Artisan
The error message Could not open input file: artisan is a frequent stumbling block for developers setting up a new Laravel environment, particularly on Windows. It often stems from a misunderstanding of how Composer and the framework itself handle dependencies. You are attempting to install artisan as if it were a standalone executable or a package you download separately. In reality, Artisan is not an external tool you need to install; it is the core entry point bundled directly with the application code.
When you run php artisan list, the CLI expects to find a file named artisan in the current directory. If that file is missing, PHP cannot locate the bootstrap script required to initialize the framework's autoloader and kernel. This usually indicates one of two scenarios: the project was downloaded incorrectly from source control without the vendor assets, or the installation process using Composer was interrupted or failed silently.
To resolve this, you must ensure the project skeleton is complete. If you are cloning a repository or extracting an archive, verify that the artisan file exists in the root folder alongside your composer.json. If the file is indeed missing after extraction, the solution is not to run a command like composer require artisan, but rather to reinstall the project dependencies from scratch.
Navigate to your project directory and execute the following command:
composer install
This command reads the composer.json file in your current directory and installs all defined dependencies into the vendor folder. Crucially, for modern Laravel versions (5.x and later), the Artisan binary is often included as part of the application's base package (laravel/laravel) or explicitly listed in the require section. Running composer install ensures that the necessary files, including the artisan script, are placed correctly relative to your project root.
On Windows, users sometimes encounter issues if they are not running the command prompt in the correct directory or if their path variables are misconfigured. Ensure you are executing the command from the exact folder where your composer.json resides. Once composer install completes successfully and populates the vendor/bin directory (and creates the artisan file in the root), the php artisan list command should return a list of available commands without error.
If you have manually removed the artisan file or deleted the project folder entirely, simply re-running composer install will regenerate it. There is no separate installation step for Artisan beyond ensuring your application's dependencies are resolved.
However, if you are starting a fresh Laravel project from scratch using Composer to create a new skeleton, ensure you use the official scaffolding command:
composer create-project laravel/laravel my-app-name
This command automatically downloads the laravel/laravel package and sets up the necessary configuration files and the Artisan script. Attempting to manually create a Laravel project by downloading only the source code without running Composer often results in missing configuration, vendor libraries, and the Artisan entry point itself.
In some legacy setups or specific hosting environments, you might see references to symlinking artisan to a path like vendor/bin/artisan. While this was common in earlier Laravel versions, modern installations typically expect the file to be located directly in the project root. If you encounter issues where the file exists but execution fails, check your PHP version compatibility and ensure no syntax errors exist in the script itself.
For production deployments or CI/CD pipelines, it is standard practice to include a build step that runs composer install before executing any Artisan commands. This guarantees the environment is self-contained and reproducible. If you are using Docker, ensure your entrypoint script explicitly runs composer install or uses composer dump-autoload if the vendor directory already exists but files are missing.
If you continue to face issues despite verifying the file's existence and running Composer, inspect the project's composer.lock file. Sometimes, a stale lock file can cause dependency resolution to fail unexpectedly. Deleting vendor/ and composer.lock before running composer install fresh often resolves these obscure path or permission problems on Windows systems.
