PHP not recognized as an internal or external command

PHP not recognized as an internal or external command is a common error Windows users running XAMPP will see. No worries though, there’s an easy fix.

The Problem

I was working with Laravel, to test it out, and needed to use ‘php artisan’ to access Laravel’s command-line tool. I cd’ed to my project folder and typed:

php artisan key:generate

The above is used to generate a 32 character application key. Kind of nice so you don’t have to create it yourself. Anyway, my command line did it’s best nope.avi impression and returned ‘php not recognized as an internal or external command’. The tutorial I was following didn’t say anything about that! Oh wait, they’re on a Mac, I’m on a Windows machine. Time to dive into the error problem.

php-pathAfter some googling, I found that I needed to adjust the PATH names so my computer would recognize PHP and MySQL. I’m running XAMPP, so I needed to point my computer to the XAMPP location. Let’s head through how to add the php path so your computer loves you enough to run php as a command.

The Solution

From the start menu, right-click ‘Computer’ and click ‘Properties’. You’ll see the image on the right pop up. Toward the bottom, click on ‘Environment Variables’.

I see the look on your face, you’re getting nervous but it’s all good. Almost finished. From this page take a look at the items in ‘System Variables’. Scroll down until you see a variable named ‘Path’ (not PATHTEXT). Click on ‘Path’ and click Edit. Go to the very end and add your path name to PHP and MySQL. For me, I have XAMPP running on a separate hard drive than C: so I had to add the following:


Notice that I had to add a semicolon at the beginning to separate it from all of the other paths. Now, for the most important part. Make sure everything is saved, close it out and then restart your computer.

The Result

Now that your computer has rebooted, try out your command again. To double-check, and in case you don’t need to use the command line for anything at the moment, go ahead and type the following:

php -v

You should get a response along the lines of:

PHP 5.4.7 (cli) (built: Sep 12 2012 23:48:31)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies

If your response is not some version of PHP, you may want to double check your steps. If you followed them correctly and are still stuck, comment below!


I hope to eventually discuss my Laravel adventures, but besides that, what else would you look to see?

Notify of
Newest Most Voted
Inline Feedbacks
View all comments
8 years ago

I can’t edit the path 🙁

5 years ago

Really useful – thanks.

John Hartley is a Director of Product Engineering at Beam Dental in Columbus, OH. With 5+ years of leadership experience he has worked in startups, agencies, and began his career as a freelance Front End Developer. Always looking to iterate, this blog is a place for him to share his knowledge as well as hone his craft, challenge assumptions, and build a strong base of leadership and management knowledge. Connect with him on LinkedIn

Would love your thoughts, please comment.x