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.
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.
After 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.
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.
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:
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?