How to add your PHP runtime directory to your Windows 10 PATH environment variable

Posted by Carl-Hugo Marcotte on October 27, 2016

How to add your PHP runtime directory to your Windows 10 PATH environment variable

Today I will explain how to add your PHP runtime directory to your Windows 10 PATH environment variable. This will give you global access to php.exe from any command prompt.

Please note that you must reopen your command prompt windows (if you had any open prior to the update).

Command prompt loads the PATH environment variable when it is first open.

Target audience

  • Windows 10 users
  • PHP developers that want PHP to be globally accessible from any command prompt (ex.: php.exe for “linting” or to start a dev. server)

Note that you are not limited to PHP, this can be any directory containing any program - ex.: npm

How to

Copy shortcut: ctrl+C Paste shortcut: ctrl+V

  1. Find your PHP installation directory and copy it somewhere (your clipboard is a good place)
    • For MAMP users it will be something like C:\MAMP\bin\php\php5.6.21 (the PHP version may vary).
  2. Right-click on the “Start menu”
  3. Click “System” win-path-01
  4. Click “Advanced system settings” win-path-02
  5. Click “Environment Variables…” win-path-03
  6. Select the “Path” variable (in your user or in the system list)
  7. Click “Edit…” win-path-04
  8. Click “New”
  9. Paste your PHP path win-path-05
  10. Click OK
  11. Click OK
  12. Click OK
  13. Close your “system window”

And voilĂ !

How to test if it worked out

  1. Open a command prompt
    1. Right-click on the start menu
    2. Click “Command Prompt” or “Command Prompt (admin)”
  2. In the command prompt, type php -?

If it displays PHP help then it worked!




Comments