简体   繁体   中英

PHP7 not installing to the command line

I have recently installed PHP 7 onto my computer to help with creating test websites with python. It has all installed and visual studio accepts the file in its path variable. However, when trying to run PHP commands from the command line, it doesn't seem to work.

Example:

Microsoft Windows [Version 10.0.17134.165]
(c) 2018 Microsoft Corporation. All rights reserved.

C:\Users\userName>php -a
'php' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\userName>

I know that this isn't a problem with command prompt because I have installed Java and Python:

Python Example:

C:\Users\userName>py
Python 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:19:30) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> print "This works!"
This works!
>>>

Likewise, I can run java commands:

C:\Users\userName>java -version
java version "9"
Java(TM) SE Runtime Environment (build 9+180)
Java HotSpot(TM) 64-Bit Server VM (build 9+180, mixed mode)

C:\Users\userName>

I have found a temporary solution to my problem, which requires that I set a path each time I want to write a PHP command:

C:\Users\userName>path C:\Program Files\PHP7

C:\Users\userName>php -a
Interactive shell

php > echo "This works!";
This works!
php >  

Any answers to how I can fix this permanently will be greatly appreciated!

You have to set path environment variable to php in case you want to use it directly with command "php".

I think this will help you: How to access PHP with the Command Line on Windows?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM