php 使用 Composer 安装 Laravel 的问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28332103/
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
Problems installing laravel with composer
提问by matt
Problem:I'm wanting to explore laravel 5, and failing miserably at installing it. I'm using this guide: http://laravel.com/docs/5.0and need someone to help me understand the instructions.
问题:我想探索 laravel 5,但在安装时惨遭失败。我正在使用本指南:http: //laravel.com/docs/5.0,需要有人帮助我理解说明。
Background and What I've Tried
背景和我的尝试
I'm running Mac OSX 10.10.2 (Yosemite) and MAMP.
我正在运行 Mac OSX 10.10.2 (Yosemite) 和 MAMP。
So far, I've downloaded Composer to my home folder using terminal. There is just a composer.phar file sitting there.
到目前为止,我已经使用终端将 Composer 下载到我的主文件夹中。那里只有一个 composer.phar 文件。
When I run:
当我运行时:
composer global require "laravel/installer=~1.1"
I get the message:
我收到消息:
Changed current directory to /Users/MYUSERNAME/.composer
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating autoload files
I assume that is ok because when I run the following in terminal, I get the composer logo and a list of options
我认为这没问题,因为当我在终端中运行以下命令时,我会得到 Composer 徽标和选项列表
~ MYUSERNAME$ composer
I'm not 100% sure what the following means, from the Laravel Docs:
我不是 100% 确定以下意思是什么,来自 Laravel Docs:
"Make sure to place the ~/.composer/vendor/bin directory in your PATH so the
laravel executable can be located by your system."
Because I can't figure it out, the following steps throw errors, such as:
因为想不通,下面的步骤抛出错误,比如:
-bash: laravel: command not found
I've been going through a few forums, and it's suggested that I need to update my PHP.ini file - this seems more related to Composer install, and not specifically Laravel. Because composer is working, this seems to be a dead end.
我浏览了一些论坛,建议我需要更新我的 PHP.ini 文件 - 这似乎与 Composer 安装更相关,而不是专门与 Laravel 相关。因为作曲家正在工作,所以这似乎是一个死胡同。
Ideally, I want to install Laravel 5 to the directory
理想情况下,我想将 Laravel 5 安装到目录
HomeFolder/sites/test
because Composer.phar is in my home folder, I think the command should be:
因为 Composer.phar 在我的主文件夹中,我认为命令应该是:
php composer laravel new sites/test
or just
要不就
composer laravel new sites/test
As mentioned, it just (correctly) throws errors.
如前所述,它只是(正确地)抛出错误。
Question:If anyone can help solve my total user error, by explaining what "Make sure to place the ~/.composer/vendor/bin directory in your PATH so the laravel executable can be located by your system." means to a n00b, that'd be really appreciated.
问题:如果有人可以通过解释“确保将 ~/.composer/vendor/bin 目录放在您的 PATH 中以便您的系统可以找到 laravel 可执行文件”来帮助解决我的总用户错误。意味着 n00b,那将是非常感激的。
Many thanks!
非常感谢!
回答by Alan Storm
Laravel is a PHP framework (makes writing PHP applications easy)
Laravel 是一个 PHP 框架(使编写 PHP 应用程序变得容易)
Composer is a PHP package and dependency manager. (makes installing and updating third party code libraries easy)
Composer 是一个 PHP 包和依赖项管理器。(使安装和更新第三方代码库变得容易)
When you run
当你跑
$ composer global require "laravel/installer=~1.1"
You're using composer to install the laravel/installer=~1.1
package into composer's "global" project folder (usually ~/.composer
). This is what installed the command line program named laravel
.
您正在使用 composer 将laravel/installer=~1.1
软件包安装到 composer 的“全局”项目文件夹中(通常为~/.composer
)。这就是安装名为laravel
.
The command line program named laravel
is a shell script for installing the PHP framework (Also named Laravel).
命名的命令行程序laravel
是一个用于安装 PHP 框架(也称为 Laravel)的 shell 脚本。
Your "Unix Path" is a list of folders where a command line script will search for an executable. Usually is has folders like /usr/bin
, /usr/local/bin
, etc. This is why when you run ls
, you're actually running /usr/bin/ls
-- the shell knows to check each folder in the path for a location. You can view your current path by typing
您的“Unix 路径”是命令行脚本将在其中搜索可执行文件的文件夹列表。通常有一个像文件夹/usr/bin
,/usr/local/bin
等等。这就是为什么当你运行ls
,你实际运行/usr/bin/ls
-外壳知道要检查每个文件夹中的位置的路径。您可以通过键入查看当前路径
$ echo $PATH
So, the problem is composer installed the laravel
command line program to a folder that's not in your unix path. You need to add this folder to your unix path. You can do this by running the following (assuming you're using bash
, which is OS X's default shell)
所以,问题是 composer 将laravel
命令行程序安装到了一个不在你的 unix 路径中的文件夹。您需要将此文件夹添加到您的 unix 路径。您可以通过运行以下命令来执行此操作(假设您使用的bash
是 OS X 的默认 shell)
$ PATH=$PATH:~/.composer/vendor/bin
If you run that, you should be able to run the laravel
command line program and continue your installation.
如果您运行它,您应该能够运行laravel
命令行程序并继续安装。
Most people add this to their .bash_profile
or .bashrc
files. The Unix Stack Exchangehas a lot of good information if you're interested in learning how to do this.
大多数人将此添加到他们的.bash_profile
或.bashrc
文件中。如果您有兴趣学习如何做到这一点,Unix Stack Exchange有很多很好的信息。
回答by lukasgeiter
You can add the directory to the PATH
variable by editing /etc/paths
.
Here's a tutorial on how to do that.
您可以PATH
通过编辑将目录添加到变量中/etc/paths
。
这是一个关于如何做到这一点的教程。
Just add a line with:
只需添加一行:
~/.composer/vendor/bin
Then the laravel new
command should work fine
然后laravel new
命令应该可以正常工作
If everything fails you can still use the composer create-project
command to make a new laravel instance:
如果一切都失败了,您仍然可以使用该composer create-project
命令来创建一个新的 Laravel 实例:
composer create-project laravel/laravel sites/test --prefer-dist
回答by ellie owen
I added C:\Users\Leon\AppData\Roaming\Composer\vendor\bin instead of ~/.composer/vendor/bin to the Path variable.
我添加 C:\Users\Leon\AppData\Roaming\Composer\vendor\bin 而不是 ~/.composer/vendor/bin 到 Path 变量。
Here is instructions on changing the path variable on Windows 10: http://windowsitpro.com/systems-management/how-can-i-add-new-folder-my-system-path
以下是在 Windows 10 上更改路径变量的说明:http: //windowsitpro.com/systems-management/how-can-i-add-new-folder-my-system-path