How do i add my php directory to the path on windows?

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

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”
  4. Click “Advanced system settings”
  5. Click “Environment Variables…”
  6. Select the “Path” variable [in your user or in the system list]
  7. Click “Edit…”
  8. Click “New”
  9. Paste your PHP path
  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

I am trying to learn how to access PHP scripts from the command line [CLI]

Below is an image from my attempt, please help. I am running Windows 7

asked Sep 5, 2011 at 11:41

JasonDavisJasonDavis

47.2k97 gold badges305 silver badges525 bronze badges

You need to add your PHP installation directory to the %PATH% environment variable, or work from the PHP installation directory.

To add it to path [The best approach - Edited for Windows 7]:

  • Right-click on a My Computer icon
  • Click Properties
  • Click Advanced system settings from the left nav
  • Click Advanced tab
  • Click Environment Variables button
  • In the System Variables section, select Path [case-insensitive] and click Edit button
  • Add a semi-colon [;] to the end of the string, then add the full file system path of your PHP installation [e.g. C:\Program Files\PHP]
  • Keep clicking OK etc until all dialog boxes have disappeared
  • Close your command prompt and open it again
  • Sorted

Alternatively, you can run cd before you try and run you command, or call your script like

answered Sep 5, 2011 at 11:44

DaveRandomDaveRandom

86.8k11 gold badges149 silver badges173 bronze badges

5

For temporary use, try this: [benefit for use npm or composer]

> SET PATH=c:\wamp\bin\php\php5.3.29\;%PATH%

For test use this:

> echo %PATH%
c:\wamp\bin\php\php5.3.29\;c:\anothers\;

Now you can access to PHP command:

> php -v
PHP 5.3.29 [cli]

answered May 17, 2018 at 2:29

Nabi K.A.Z.Nabi K.A.Z.

8,7466 gold badges53 silver badges71 bronze badges

1

Easy Way: Run CMD then type

C:\wamp\bin\php\php5.4.3\php.exe -f "C:\wamp\www\timenow.php"

Change the last part for a different script, and make sure you have the same version php folder as I do. [php5.4.3]

answered Feb 3, 2014 at 16:02

1

On 2020 and with Windows 10 there's an easier way to achieve this.

1- Download composer at //getcomposer.org/Composer-Setup.exe

2- Install it as you install any program on windows and [important] when it asks you the path to PHP, browse thru the correct path [for example: c:/wamp/bin/php.exe]

FINNISHED! Close the cmd and reopen and you can run PHP on your command line and also COMPOSER [composer is actually very needed if you use PHP]

answered Jul 4, 2020 at 21:24

gtamborerogtamborero

2,47923 silver badges23 bronze badges

you can run cd before you try and run you command, or call your script like

answered Dec 16, 2021 at 4:18

Not the answer you're looking for? Browse other questions tagged php command-line command-line-interface or ask your own question.

How do I add a directory to my path in Windows?

2 Answers.
Step 1 - Click on the Windows icon..
Step 2 - Click on the Settings icon..
Step 3 - Click on System..
Step 4 - Click on About..
Step 5 - Click on System info..
Step 6 - Click on Advanced system settings..
Step 7 - Click on Environment variables....
Step 8 - Select Path row and then click Edit..

How do I find my PHP path in CMD?

Show activity on this post..
First open your cmd..
Then go to php folder directory, Suppose your php folder is in xampp folder on your c drive. Your command would then be: cd c:\xampp\php..
After that, check your version: php -v..

How do I add to my System path?

Direct link to this answer.
Right-click on the Start Button..
Select “System” from the context menu..
Click “Advanced system settings”.
Go to the “Advanced” tab..
Click “Environment Variables…”.
Click variable called “Path” and click “Edit…”.
Click “New”.
Enter the path to the folder containing the binary you want on your PATH..

How do I add to path in Windows 10?

Windows 10 and Windows 8.
In Search, search for and then select: System [Control Panel].
Click the Advanced system settings link..
Click Environment Variables. ... .
In the Edit System Variable [or New System Variable] window, specify the value of the PATH environment variable..

Chủ Đề