375

When trying to create a new laravel project, The following error appears on the CLI:

Could not open input file: artisan

Script php artisan clear-compiled handling the post-install-cmd event returned with an error

I am using the latest version of XAMPP v3.2.1 with PHP 5.5.15 and with mcrypt enabled (made sure of that by issuing the command php -m). And I am running windows 8.1

Community
  • 1
  • 1
wessodesigner
  • 4,485
  • 3
  • 16
  • 9
  • 2
    Looks like this question is old. Did you figure out the issue? If you wouldn't mind, share the question with the rest of the squad :) – Zarathuztra Apr 25 '15 at 15:11
  • 27
    I think, php artisan is to be called from the root folder of laravel site. or else this error will popup. – Eugine Joseph May 21 '17 at 04:47
  • You need to run your artisan command at the same level as your artisan directory. This will make sure you are in your Laravel project – Sweet Chilly Philly Apr 30 '18 at 02:33
  • 2
    Sidenote: Initially I thought that when `php artisan ...` was called, it was some sort of option for the `php` command. Turns out it refers to a file named `artisan` which is in the root of your laravel project. It should really be called `artisan.php` since it is an actual php script but the extension is omitted for brevity purposes. – Flame Mar 11 '19 at 12:38
  • Just try and execute the command in directory where all laravel code resides. Happened with me too, I was trying to run the command in project's root folder, but the code was in a sub directory – Ajjay Arora Dec 15 '19 at 16:26
  • Same Issue here. I was running the command in the root folder that houses many projects. You need to run that command in the folder where the Laravel code resides for that specific project. – MosesK Jul 30 '21 at 11:06
  • @Flame Thank you! I see now, it runs the php script called artisan. – user2924019 May 25 '22 at 16:17
  • make sure you have artisan.php file on root of your laravel application else you will face error like "Could not open input file: artisan". – Vatsal Ajmera May 30 '23 at 07:13

25 Answers25

505

You need to first create Laravel project and if you already have one you need to go to this project dir using cd command in terminal for example cd myproject.

Now you will be able to run any artisan commands, for example running php artisan will display you list of available commands.

Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291
  • 2
    This error appears when I am attempting to create a new laravel project: cd xampp/htdocs then composer create-project laravel/laravel newLaravelProject It starts to download all the required dependencies, and suddenly this error appears. – wessodesigner Oct 04 '14 at 16:44
  • 2
    If you have moved your app folder with .env, vendor folder, config folder...etc to some where else, you may have to change directory root to this location. – Eranda Aug 03 '15 at 23:43
  • This should be the selected answer. Worked perfectly! – Chad Sep 29 '18 at 23:32
  • Agreed. correct answer here. I didn't know that it only worked from the project root folder. – raw-bin hood Sep 30 '20 at 13:56
  • I am facing an issue like this one if anyone ca help with it https://stackoverflow.com/questions/64983129/cant-run-php-artisan-on-ubuntu-terminal-on-windows-10-machine – Mounir Tanbouzeh El Husseini Nov 25 '20 at 06:35
185

You cannot use php artisan if you are not inside a laravel project folder.

That is why it says 'Could not open input file - artisan'.

Yevgeniy Afanasyev
  • 37,872
  • 26
  • 173
  • 191
  • 2
    of course you have to do a `composer install` almost one time –  Jan 10 '19 at 17:35
  • 1
    I tried to make a migration from the migration folders, I hasd this message, you've got to be at the root of your application (where composer.json resides) to make it work – Yvon Huynh Aug 09 '20 at 06:35
31

If you project is at /home/forge/laravel-project/

You can properly execute your artisan like this

php /home/forge/laravel-project/artisan ...

code-8
  • 54,650
  • 106
  • 352
  • 604
17

Most probably you are not in the right directory!

LinusGeffarth
  • 27,197
  • 29
  • 120
  • 174
zaffar
  • 679
  • 6
  • 13
16

I just needed to make artisan executable.

chmod +x artisan

...and it works without the php prefix then.

Kevin Carmody
  • 2,311
  • 2
  • 23
  • 23
12

Make Sure your current directory is your project-name

for example your project name is demo and location is f:/demo
f:demo> php artisan serve
Happy Patel
  • 2,259
  • 1
  • 16
  • 25
11

First, be sure to be in the laravel project folder or else the terminal won't be able to locate the artisan file in the project directory and any subsequent request you pulled to start a server would be rejected.

Demo

Let's say our laravel project name is blog and located in C:\laravel We then have: C:\laravel\blog

Where to open terminal

Navigate to the C:\laravel\blog directory and open the command window (terminal). Input the code below:

Laravel terminal code to start server

php artisan serve --host 127.0.0.1

John Zenith
  • 472
  • 5
  • 10
6

First create the project from the following link to create larave 7 project: Create Project

Now you need to enter your project folder using the following command:

cd myproject

Now try to run artisan command, such as, php artisan.

Or it may happen if you didn't install compose. So if you didn't install composer then run composer install and try again artisan command.

Md Riadul Islam
  • 1,273
  • 11
  • 25
5

If it is your first install of laravel then create another directory/folder inside the laravel directory and then move to that empty folder and create another project using the command below:

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

This will create a new project named "blog", then go back to parent laravel directory and now you can run this command:

php artisan serve

You will receive the return such as:

laravel deployment server started: http://localhost:8000

See attached image enter image description here

A.Aleem11
  • 1,844
  • 17
  • 12
4

I checked out an existing Laravel project, which did not have this script. Even a find / -name 'artisan' produced no results. The solution turned out to be simple, if a bit weird:

curl -L 'https://raw.githubusercontent.com/laravel/laravel/v4.2.11/artisan' > artisan

You probably want to choose a tagged version that matches your installed version of Laravel.

DavidM
  • 1,417
  • 1
  • 13
  • 16
2

If you're running your Laravel project in Vagrant and have just SSH-ed into the virtual machine, don't forget to cd /vagrant before you try running artisan commands!

TeeJay
  • 1,593
  • 3
  • 21
  • 33
2

After struggling with this issue, I found out that you need to find where artisan resides by running sudo find / -name artisan, and from there run the command php artisan ....

soBusted
  • 197
  • 3
  • 18
1

This error happens because you didn't install composer on your project.

run composer install command in your project path.

Ali Lashini
  • 427
  • 1
  • 5
  • 17
1

You need to first create Laravel project and if you already have one you need to go to this project dir using cd command in terminal for example cd myproject.

Example : C:\xampp new\htdocs\project laravel\LaravelProject>php artisan serve

Now you will be able to run any artisan commands, for example running php artisan will display you list of available commands.

enter image description here

Aslam Khan
  • 382
  • 2
  • 2
1

Mainly this may happen because your Laravel project opens on the wrong path. Just open the folder again in your code editor. That's what happened to me when I got the same error.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 18 '22 at 05:33
1

None of the solution worked for me. You can use these commands for solving the issue:

Remove bootstrap/cache/config.php file then:

composer dumpautoload
composer update

Remove vendor folder then:

composer install

If still not solved, your last option maybe to create new Laravel project: With new folder:

composer create-project --force laravel/laravel my-joyful-project

Without new folder:

composer create-project --force laravel/laravel .

It should solve the issue. If still no, make sure you do not have older laravel version. And lastly, make sure that it is Laravel project you are working on, not Silverstripe. They are both using composer and have similar configuration files. Easy to mess up or maybe not :)

Elmar
  • 2,235
  • 24
  • 22
1

I had the same issue. I have fixed it by doing the following steps:

  1. removed vendor folder rm -Rf vendor
  2. tried to install the composer packages again: composer install --no-dev
  3. ran the required php artisan command again

Worked!

Ramin
  • 351
  • 2
  • 7
0

After installing composer, you need to create the project:

composer create-project laravel/laravel /path/to/tour/project

You can see the documentation, for your php version the lastest Laravel you can install is 5.0.

Now days here is the lastest version and require > php7.0. Here is the documentation.

Talan
  • 81
  • 2
  • 6
0

What did the trick for me was to do cd src from my project directoy, and then use the php artisan command, since my artisan file was in the src folder. Here is my project structure:

project
|__ config
|__ src
    |__ app
    |__ ..
    |__ artisan  // hello there!
    |__ ...
|__ ...
Aleksandar
  • 3,558
  • 1
  • 39
  • 42
0

if you re in say my-project/app/somefolder run in terminal cd .. two times to get in my-project/ folder

CodeToLife
  • 3,672
  • 2
  • 41
  • 29
0

Another thing to note that if you have a symbolic link from a non public location which hosts your project code to say public_html - running php artisan in the symbolic link location (public_html) will result in this error. You seem to need to be in the actual project directory for php artisan to work.

SupaMonkey
  • 876
  • 2
  • 9
  • 25
0

For those people that are having the same error on cPanel terminal specifically.

Now you need to enter into your project root or public_html folder in the terminal using the following command:

cd public_html

Now you will be able to run any artisan commands.

php artisan config:clear

enter image description here

Edwinfad
  • 515
  • 6
  • 14
0

Based on my experience, you must check if the artisan file is in your project folder. I had the same error, and when I check the artisan, it was not present. You can easily copy any artisan file from any existing or already working project and paste it into your new project.

Or you may download it here: artisan file

iAmBorgy
  • 73
  • 9
0

In my case, I was trying to run artisan with wrong user. ex: the project was belonging to fooo user but I was baaar user when I run the command. Simply changing the user or run with other user fix the problem.

Change to other user

sudo su - fooo
# then run the command
php artisan ...

Run with other user

sudo su - fooo php artisan ...
Anji
  • 517
  • 2
  • 10
-1

I have the same issue. I am also in the laravel project directory. what works for me is just change the permission of the artisan file.

For linux

chmod 777 artisan

For windows

  • use the file property
Pranay kumar
  • 1,983
  • 4
  • 22
  • 51