为什么我不能在 Laravel 路径中使用 'php artisan' cmd (Win)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15514444/
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
Why can't I use 'php artisan' cmd in Laravel path (Win)
提问by Kai
I have tried to learn Laravel in Ubuntu and the command "php artisan' worked in the laravel folder path in the terminal.
我尝试在 Ubuntu 中学习 Laravel,并且命令“php artisan”在终端的 Laravel 文件夹路径中起作用。
I just start to do it in Win7, I typed "cd c:\wamp\www\myproject" in cmd.exe to change the path to the laravel folder (artisan file is in this folder).
我刚开始在Win7下做,我在cmd.exe中输入“cd c:\wamp\www\myproject”来更改laravel文件夹的路径(artisan文件在这个文件夹中)。
After that I tried "php artisan" but I got this message "'php' is not recognized as an internal or external command, operable program or batch file."
之后,我尝试了“php artisan”,但收到此消息“'php' 未被识别为内部或外部命令、可运行的程序或批处理文件。”
Did I miss something? The command line showed there is C:\wamp\www\myproject>php artisan and I have double checked the file path is right.
我错过了什么?命令行显示有 C:\wamp\www\myproject>php artisan 并且我已经仔细检查了文件路径是否正确。
Which step did I do wrong?
我哪一步做错了?
回答by castis
The error is occurring because the windows command line doesn't know where to find the php.exe binary.
发生错误是因为 Windows 命令行不知道在哪里可以找到 php.exe 二进制文件。
In Windows 7 click START and then type 'environment' into the start-menu search bar. Choose 'edit environment variables for your account'. In previous version of windows right-click My Computer then click properties. Go to advanced tab in the properties window and click the button on the bottom labelled, "Environment Variables."
在 Windows 7 中,单击开始,然后在开始菜单搜索栏中键入“环境”。选择“为您的帐户编辑环境变量”。在以前版本的 Windows 中,右键单击“我的电脑”,然后单击“属性”。转到属性窗口中的高级选项卡,然后单击底部标有“环境变量”的按钮。
Now, find the PATH environment variable and add the path to your PHP binary to it. Paths are delimited with semi-colons.
现在,找到 PATH 环境变量并将 PHP 二进制文件的路径添加到其中。路径用分号分隔。
An example PATH variable may look like:
示例 PATH 变量可能如下所示:
C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;D:\apps\Git\bin
Simply add the path to your PHP binary to the end, don't forget the intervening semi-colon. The path to my PHP binary is D:\work\apps\xampp177\php so my PATH variable will look like this:
只需将 PHP 二进制文件的路径添加到最后,不要忘记中间的分号。我的 PHP 二进制文件的路径是 D:\work\apps\xampp177\php 所以我的 PATH 变量看起来像这样:
C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;D:\apps\Git\bin;D:\work\apps\xampp177\php
Notice that the path doesn't contain php.exe. The path is only the folder which contains php.exe.
请注意,该路径不包含 php.exe。路径只是包含 php.exe 的文件夹。
After the PATH has been saved, close your CLI, reopen it, and you should have no further problems using artisan.
保存 PATH 后,关闭 CLI,重新打开它,使用 artisan 应该不会再有问题了。