316
votes

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

19
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
I think, php artisan is to be called from the root folder of laravel site. or else this error will popup.Eugine Joseph
You need to run your artisan command at the same level as your artisan directory. This will make sure you are in your Laravel projectSweet Chilly Philly
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
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 directoryAjjay Arora

19 Answers

456
votes

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.

170
votes

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'.

25
votes

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

You can properly execute your artisan like this

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

14
votes

Most probably you are not in the right directory!

12
votes

I just needed to make artisan executable.

chmod +x artisan

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

9
votes

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

3
votes

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.

3
votes

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

3
votes

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 ....

2
votes

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!

2
votes

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

run composer install command in your project path.

2
votes

Make Sure your current directory is your project-name

f:demo> php artisan serve
1
votes

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.

1
votes

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!
    |__ ...
|__ ...
1
votes

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.

1
votes

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

1
votes

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

1
votes

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.

1
votes

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