Just Learn Code

Fixing ‘php is not recognized’ error on Windows: Step-by-step guide

“Troubleshooting ‘php’ is not recognized as an internal or external command error”

Have you encountered the error message “‘php’ is not recognized as an internal or external command” when using PHP on your Windows computer? This error can be frustrating, especially for those who are not very familiar with the ins and outs of Windows environment variables.

Fear not! In this article, we will walk you through the steps to troubleshoot this error and get your PHP up and running smoothly.

Finding PHP installation directory

The first step in troubleshooting this error is to locate your PHP installation directory. This directory is typically the location where you extracted the PHP files when you first installed it on your computer.

If you’re not sure where it is located, simply open File Explorer, navigate to the drive where PHP is installed, and use the search function to look for files with the .php extension.

Adding PHP folder path to Windows environment variable

Once you have found your PHP installation directory, the next step is to add the path to this directory to your Windows environment variable. This variable is what Windows uses to locate executable files when you type a command in the Command Prompt.

To add the PHP folder to your environment variable, follow these steps:

1. Press the Windows key + R to open the Run dialog box.

2. Type “sysdm.cpl” and press Enter to open the System Properties window.

3. Click on the “Advanced” tab and then click on the “Environment Variables” button.

4. Under “System Variables”, scroll down until you find the “Path” variable and click on “Edit”.

5. Click “New” and type in the path to your PHP installation directory.

6. Click “OK” to save the changes.

Restarting Command Prompt and running php command

Now that you have added the PHP folder path to your environment variable, you need to restart the Command Prompt for the changes to take effect. To do this, simply close all Command Prompt windows and open a new one.

Once you have opened a new Command Prompt window, type in the “php” command and hit Enter. If everything has been set up correctly, you should see a list of PHP commands and their descriptions.

“Using PHP from another source”

What if you want to use PHP from another source, such as the official Windows PHP website? While the process is a little bit different, it is still relatively straightforward.

Here’s how to do it:

Downloading and installing PHP from windows.php.net

The first step is to download the latest version of PHP for Windows from the official website. Once you have downloaded the zip file containing PHP, extract it to a folder of your choice.

Adding PHP downloaded from windows.php.net to Windows environment variable

Next, you need to add the path to the PHP folder where you extracted the files to your Windows environment variable. To do this, follow the same steps outlined above for adding the PHP folder path to your environment variable.

However, this time, instead of adding the path to your original PHP installation directory, add the path to the folder where you extracted the files from the downloaded zip file.

Restarting Command Prompt and running php command

After you have added the path to the downloaded PHP folder to your environment variable, you need to restart the Command Prompt for the changes to take effect. Once you have a new Command Prompt window open, navigate to the directory where you extracted the PHP files and type in the “php” command.

If everything has been set up correctly, you should see a list of PHP commands and their descriptions.

Conclusion

In summary, troubleshooting the “‘php’ is not recognized as an internal or external command” error and using PHP from another source are relatively easy tasks. By following the steps outlined in this article, you can get your PHP up and running smoothly in no time.

Remember to always make sure that the path to your PHP installation directory or downloaded PHP folder is added to your Windows environment variable to avoid encountering this error in the future. In this article, we discussed the common error message of “‘php’ is not recognized as an internal or external command” that Windows users encounter while trying to run PHP.

We also provided step-by-step guidelines on how to troubleshoot this error by finding the PHP installation directory, adding PHP folder path to Windows environment variables, and restarting Command Prompt to run the PHP command. Additionally, we explained how to use PHP from another source by downloading and installing PHP from windows.php.net, adding PHP downloaded from this source to Windows environment variables, and restarting Command Prompt to run the PHP command again.

As a key takeaway, always ensure that the path to PHP installation directory or downloaded PHP folder is correctly added to the Windows environment variable to avoid encountering such errors in the future.

Popular Posts