如何为 PHP 设置 env 变量?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2736528/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 07:30:58  来源:igfitidea点击:

How to set the env variable for PHP?

phpwindowswamp

提问by Bruce

I am using WAMP. I want to use php from the command prompt. What is the entry in PATH env variable for this ?

我正在使用 WAMP。我想在命令提示符下使用 php。PATH 环境变量中的条目是什么?

采纳答案by codaddict

You need to put the directory that has php.exein you WAMPinstallation into your PATH. It is usually something like C:\wamp\xampp\php

你需要把具有目录php.exe在您WAMP安装到您PATH。它通常是这样的C:\wamp\xampp\php

回答by Pekka

You need to add the PHP directory to your path. On the command line (e.g. in a batch file), it would look like this:

您需要将 PHP 目录添加到您的路径中。在命令行上(例如在批处理文件中),它看起来像这样:

SET PATH=%PATH%;C:\your\wamp\path\php

if in doubt, it's the directory containing the php.exe.

如果有疑问,它是包含php.exe.

You can also pre-set the path in Windows' control panel. See hereon how to do this in Windows 7 for example.

您还可以在 Windows 的控制面板中预先设置路径。例如,请参阅此处了解如何在 Windows 7 中执行此操作。

Be aware that if you call the PHP executable from an arbitrary directory, that directory will be the working directory. You may need to adjust your scripts so they use the proper directories for their file operations (if there are any).

请注意,如果您从任意目录调用 PHP 可执行文件,该目录将是工作目录。您可能需要调整脚本,以便它们使用正确的目录进行文件操作(如果有)。

回答by Mukesh

Follow this for Windows operating system with WAMP installed.

对于安装了 WAMP 的 Windows 操作系统,请遵循此操作。

System > Advanced System Settings > Environment Variables
Click new

Variable name  : path
Variable value : c:\wamp\bin\php\php5.3.13\


Click ok

回答by Sakil

For windows: Go to your "system properties" please.then follow as bellow.

对于 Windows:请转到您的“系统属性”。然后按照以下步骤操作。

Advanced system settings(from left sidebar)->Environment variables(very last option)->path(from lower box/system variables called as I know)->edit

高级系统设置(来自左侧边栏)-> 环境变量(最后一个选项)-> 路径(来自下框/系统变量,据我所知)-> 编辑

then concatenate the "php" location you have in your pc (usually it is where your xampp is installed say c:/xampp/php)

然后连接你在你的电脑中的“php”位置(通常它是你的 xampp 的安装位置,比如 c:/xampp/php)

N.B : Please never forget to set semicolon (;) between your recent concatenated path and the existed path in your "Path"

注意:请永远不要忘记在您最近连接的路径和“路径”中的现有路径之间设置分号 (;)

Something like C:\Program Files\Git\usr\bin;C:\xampp\php

类似于 C:\Program Files\Git\usr\bin;C:\xampp\php

Hope this will help.Happy coding. :) :)

希望这会有所帮助。快乐编码。:) :)

回答by Nikunj K.

You May use setkeyword for set the path

您可以使用set关键字来设置路径

set path=%path%;c:/wamp/bin/php/php5.3.0

if all the path are set in path variables

如果所有路径都设置在路径变量中

If you want to see all path list. you can use

如果要查看所有路径列表。您可以使用

set %path%

you need to append your php path behind this path.

您需要在此路径后面附加您的 php 路径。

This is how you can set environment variable.

这是您可以设置环境变量的方法。

回答by Boris Guéry

It depends on your OS, but if you are on Windows XP, you need to go to Systems Properties, then Advanced, then Environment Variables, and include the php binary path to the %PATH% variable.

这取决于您的操作系统,但如果您使用的是 Windows XP,则需要转到系统属性,然后是高级,然后是环境变量,并将 php 二进制路径包含到 %PATH% 变量中。

Locate it by browsing your WAMP directory. It's called php.exe

通过浏览您的 WAMP 目录找到它。它叫做 php.exe

回答by Kamilos

Try display phpinfo() by file and check this var.

尝试按文件显示 phpinfo() 并检查此变量。