• 10

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191


File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

How to access PHP with the Command Line on Windows?

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


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 <PHP installation path> before you try and run you command, or call your script like <FULL file system path of php.exe> <path to script>

  • 83
Reply Report
      • 2
    • On Windows 8: Press WIN + Q, enter "environ" and choose the first entry "Edit the system environment variables", saves you some mouse clicks. Proceed at step 5.
    • It's also worth noting that on all versions of Windows you can open the system properties dialog (first two steps) by hitting Win + pause/break
      • 2
    • I tried this on windows 10 and it said php.exe not reconized, are there any other steps i need to take?
    • @DustinPoissant are you sure you tried to use it in a new command prompt? You can type set path in a command prompt to inspect the current value of the %path% environment variable and check that the installation path of PHP is present in that session
      • 2
    • I restarted my computer and it work. Apparently with windows 10 after you add something to the PATH you have to restart sometimes.

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%

Now you can access to PHP command:

> php -v
PHP 5.3.29 (cli)
  • 7
Reply Report

On 2020 over Windows 10 there's an easier way to achieve this. I tried the way of @DaveRandom but it didn't work...

1- Download composer at https://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)

  • 0
Reply Report

Warm tip !!!

This article is reproduced from Stack Exchange / Stack Overflow, please click

Trending Tags

Related Questions