93

I want to create migrations in Laravel but according to the tutorials I need the Artisan CLI. The php command works fine and I'm on Windows. I type in php artisan or php artisan list and I get the following error:

Could not open input file: artisan

I wasn't able to find any guide in the documentation nor in Google. How can I install Artisan?

1
  • 6
    It took a while for me to realize Laravel's CLI tools are to be run from the project's root folder (the one just above app. I still forget where I am every now and then in the middle of a project. Typing pwd sure helps.
    – mike
    Mar 6, 2014 at 7:49

5 Answers 5

138

Use the project's root folder

Artisan comes with Laravel by default, if your php command works fine, then the only thing you need to do is to navigate to the project's root folder. The root folder is the parent folder of the app folder. For example:

cd c:\Program Files\xampp\htdocs\your-project-name

Now the php artisan list command should work fine, because PHP runs the file called artisan in the project's folder.

Install the framework

Keep in mind that Artisan runs scripts stored in the vendor folder, so if you installed Laravel without Composer, like downloading and extracting the Laravel GitHub repo, then you don't have the framework itself and you may get the following error when you try to use Artisan:

Could not open input file: artisan

To solve this you have to install the framework itself by running composer install in your project's root folder.

4
  • 1
    Note: on a live production server (i.e., Linux/Apache) the Laravel site is not run from the publicly available web folder (htdocs) but from the user's folder.
    – mike
    Mar 6, 2014 at 7:54
  • 2
    After running composer install, I still get an error when it attempts to run php artisan optimize with the error looking like {"error":{"type":"ErrorException","message":"file_put_contents(\/meta\/services.json): failed to open stream: No such file or directory" Sep 8, 2015 at 17:36
  • This is a great start for people who still have problems with artisan. This post can help too.
    – user7503126
    Jan 25, 2019 at 13:36
  • and if artisan still does not work then try php artisan somecommand Feb 2, 2021 at 11:05
13

You just have to read the laravel installation page:

  1. Install Composer if not already installed
  2. Open a command line and do:
composer global require "laravel/installer"

Inside your htdocs or www directory, use either:

laravel new appName

(this can lead to an error on windows computers while using latest Laravel (1.3.2)) or:

composer create-project --prefer-dist laravel/laravel appName

(this works also on windows) to create a project called "appName".

To use "php artisan xyz" you have to be inside your project root! as artisan is a file php is going to use... Simple as that ;)

1
  • 3
    This answer is about installing Laravel, not Artisan.
    – totymedli
    Sep 25, 2016 at 18:28
5

While you are working with Laravel you must be in root of laravel directory structure. There are App, route, public etc folders is root directory. Just follow below step to fix issue. check composer status using : composer -v

First, download the Laravel installer using Composer:

composer global require "laravel/installer"

Please check with below command:

php artisan serve

still not work then create new project with existing code. using LINK

4
  • 1
    Only your last sentence tries to answer the question and even that is utterly ambiguous and scant, not to mention that it was already posted in another answer in greater detail. Please read the help on how to answer.
    – totymedli
    Dec 12, 2016 at 14:47
  • @totymedli. Please Improve rating for provided answer. Let me know still any mis. Oct 3, 2017 at 7:32
  • You just added more artisan commands. That still doesn't solve the issue. The artisan CLI itself doesn't work, what am I supposed to do with the command then? Also the question has been answered for 3 years now by myself. Check out what was the solution. Unless you provide a better answer you are kinda late from this game...
    – totymedli
    Oct 3, 2017 at 10:39
  • hello from the future, still seeing this issue occuring. after trying out the majority of these answers it still has not yet solved mine. i cannot run php artisan serve without recieving some error -- Illuminate\Foundation\Application x/bootstrap/app.php:14
    – Pwntastic
    Oct 22, 2022 at 7:29
2

Explanation: When you install a new laravel project on your folder(for example myfolder) using the composer, it installs the complete laravel project inside your folder(myfolder/laravel) than artisan is inside laravel.that's, why you see an error,

Could not open input file: artisan

Solution: You have to go inside by command prompt to that location or move laravel files inside your folder.

1
  • This answer provides no additional info to what other answers already stated. This solution was already explained in much more detail than this vague guide.
    – totymedli
    Oct 22, 2018 at 14:17
-7

in laravel, artisan is a file under root/protected page

for example,

c:\xampp\htdocs\my_project\protected\artisan

you can view the content of "artisan" file with any text editor, it's a php command syntax

so when we type

php artisan

we tell php to run php script in "artisan" file

for example:

php artisan change

will show the change of current laravel version

to see the other option, just type

php artisan

1
  • 3
    This has nothing to do with the question. Doesn't answers why the artisan command isn't working, it just lists a few artisan commands you can't even try because, well... the command is not working.
    – totymedli
    Sep 2, 2014 at 10:23

Not the answer you're looking for? Browse other questions tagged or ask your own question.