Add PHP to Your Windows Path Variable

Like many developers, I write code on my local machine. WAMP is my tool of choice as the majority of my projects are PHP based. Certain situations require me to run PHP tasks from the Windows command prompt (ie: reindexing Magento databases). In order to run PHP from the command prompt in Windows, you need to tell Windows where PHP is located by adding its location to your Windows Path variable. Let’s do it.

  1. Click the Start menu orb and go to Computer.

    Screenshot of the Computer option in the Windows start menu
    Windows Start Menu
  2. In the Computer window click the System properties button on navigation bar.

    Screenshot of the My Comuter window in Windows
    My Computer
  3. In the System properties window click the Advanced system settings link.

    Screenshot of the System Properties window in Windows
    System Properties
  4. In the Advanced system settings window click the Environment Variables… button.

    Screenshot of the Advanced System Properties window in Windows
    Advanced System Properties
  5. In the Environment Variables window select the path in the user variables section and click the Edit… button.

    Screenshot of the Environment Variables window in Windows
    Environment Variables
  6. In the Edit User Variable window place your cursor at the end of the contents within the Variable value: input and add the location of PHP to that string. In a typical WAMP installation, PHP is located in C:\wamp\bin\php\php.#.#.# where #.#.# corresponds to the version of PHP that you are running.

    Note: locations are separated by semicolons. So, make sure there is a semicolon before you define the location of PHP in the variable value.

    Screenshot of the Edit User Variable window in Windows
    Edit User Variable
  7. After you have entered the location of PHP, click the OK button and restart your command prompt. Congrats, you can now run PHP from the Windows command prompt!

    Screenshot of the Edit User Variable window in Windows
    Edit User Variable (edited)

12 thoughts on “Add PHP to Your Windows Path Variable”

  1. Pingback: Document Moved
  2. C:xampphtdocsmagento>php bin/magento setup:upgrade
    ‘php’ is not recognized as an internal or external command,
    operable program or batch file.

    i have this error can you help me out.

Leave a Reply

Your email address will not be published. Required fields are marked *