php 如何从任何地方运行作曲家?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11333230/
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
How to run composer from anywhere?
提问by ziiweb
I have just installed composer in my /usr/binfolder, so when from that folder I run php composer.pharI get the help info about composer. But, when I try to run the same from other folder I get Could not open input file: composer.phar.
我刚刚在我的/usr/bin文件夹中安装了 composer ,所以当我从那个文件夹运行时,php composer.phar我会得到关于 composer 的帮助信息。但是,当我尝试从其他文件夹运行相同的文件时,我得到Could not open input file: composer.phar.
How to call php composer.pharfrom every where without problems?
如何php composer.phar从任何地方拨打电话都没有问题?
采纳答案by Maerlyn
composer.phar can be ran on its own, no need to prefix it with php. This should solve your problem (being in the difference of bash's $PATH and php's include_path).
composer.phar 可以单独运行,不需要在它前面加上php. 这应该可以解决您的问题(在 bash 的 $PATH 和 php 的 include_path 之间存在差异)。
回答by quantme
You can do a global installation(archived guide):
Since Composer works with the current working directory it is possible to install it in a system wide way.
- Change into a directory in your path like
cd /usr/local/bin- Get Composer
curl -sS https://getcomposer.org/installer | php- Make the phar executable
chmod a+x composer.phar- Change into a project directory
cd /path/to/my/project- Use Composer as you normally would
composer.phar install- Optionally you can rename the
composer.phartocomposerto make it easier
由于 Composer 使用当前工作目录,因此可以以系统范围的方式安装它。
- 更改为您路径中的目录,例如
cd /usr/local/bin- 获取作曲家
curl -sS https://getcomposer.org/installer | php- 使 phar 可执行
chmod a+x composer.phar- 切换到项目目录
cd /path/to/my/project- 像往常一样使用 Composer
composer.phar install- (可选)您可以将 重命名为以使其更容易
composer.pharcomposer
Update: Sometimes you can't or don't want to download at /usr/local/bin(some have experienced user permissions issues or restricted access), in this case you can try this
更新:有时你不能或不想下载/usr/local/bin(有些人遇到了用户权限问题或访问受限),在这种情况下你可以试试这个
- Open terminal
curl -sS http://getcomposer.org/installer | php -- --filename=composerchmod a+x composersudo mv composer /usr/local/bin/composer
- 打开终端
curl -sS http://getcomposer.org/installer | php -- --filename=composerchmod a+x composersudo mv composer /usr/local/bin/composer
Update 2: For Windows 10 and PHP 7 I recommend this tutorial. Personally I installed Visual C++ Redistributable for Visual Studio 2017 x64before PHP 7.3 VC15 x64 Non Thread Safe version (check which versions of both in the PHP for Windowspage, side menu). Read carefully and maybe the enable-extensions section could differ (extension=curlinstead of extension=php_curl.dll). Works like a charm, good luck!
更新 2:对于 Windows 10 和 PHP 7,我推荐本教程。我个人在 PHP 7.3 VC15 x64 非线程安全版本之前为 Visual Studio 2017 x64安装了Visual C++ Redistributable(在PHP for Windows页面,侧边菜单中检查两者的版本)。仔细阅读,也许 enable-extensions 部分可能有所不同(extension=curl而不是extension=php_curl.dll)。像魅力一样工作,祝你好运!
回答by Randika Vishman
How to run Composer From Anywhere (on MacOS X) via Terminal
如何通过终端从任何地方(在 MacOS X 上)运行 Composer
Background:
背景:
Actually in getComposer website it clearly states that, install the Composer by using the following curl command,
实际上在 getComposer 网站中它明确指出,使用以下 curl 命令安装 Composer,
curl -sS https://getcomposer.org/installer |php
And it certainly does what it's intended to do. And then it says to move the composer.pharto the directory /usr/local/bin/composerand then composer will be available Globally, by using the following command line in terminal!
它肯定会做它打算做的事情。然后它说将composer.phar移动到目录/usr/local/bin/composer然后 composer 将在全球可用,通过在终端中使用以下命令行!
mv composer.phar /usr/local/bin/composer
Question:
题:
So the problem which leads me to Google over it is when I executed the above line in Mac OS X Terminal, it said that, Permission denied. Like as follows:
所以导致我去谷歌的问题是当我在 Mac OS X 终端中执行上述行时,它说,权限被拒绝。像下面这样:
mv: rename composer.phar to /usr/local/bin/composer: Permission denied
Answer:
回答:
Following linkled me to the solution like a charm and I'm thankful to that. The thing I just missed was sudocommand before the above stated "Move" command line. Now my Move command is as follows:
以下链接使我像魅力一样找到了解决方案,我对此表示感谢。我刚刚错过的是上述“移动”命令行之前的sudo命令。现在我的移动命令如下:
sudo mv composer.phar /usr/local/bin/composer
Password:
It directly prompts you to authenticate yourself and see if you are authorized. So if you enter a valid password, then the Moving will be done, and you can just check if composer is globally installed, by using the following line.
它直接提示您进行身份验证并查看您是否获得授权。因此,如果您输入有效的密码,则将完成移动,您可以使用以下行检查是否全局安装了 composer。
composer about
I hope this answer helped you to broaden your view and finally resolve your problem.
我希望这个答案能帮助您拓宽视野并最终解决您的问题。
Cheers!
干杯!
回答by Mahendran Sakkarai
First install the composer like mentioned in the composer installation documentation. I just added here for reference.
首先像 Composer安装文档中提到的那样安装 Composer。我只是在这里添加以供参考。
curl -sS https://getcomposer.org/installer | php
curl -sS https://getcomposer.org/installer | php
and then move the file to '/usr/local/bin'.
然后将文件移动到“/usr/local/bin”。
sudo mv composer.phar /usr/local/bin/composer
sudo mv composer.phar /usr/local/bin/composer
Try to run composer -V. If you get a output like Composer versionfollowed by the version number then the composer is installed successfully.
尝试运行composer -V。如果您得到类似Composer version版本号的输出,则 Composer 安装成功。
If you get any output like composer: command not foundmeans use the following command to create a alias for the composer. So it will be executed globally.
如果您得到任何类似的输出,请composer: command not found使用以下命令为 Composer 创建别名。所以会全局执行。
alias composer='/usr/local/bin/composer'
alias composer='/usr/local/bin/composer'
Now if you run composer -Vmeans you will get the output as Composer Versionfollowed by the version number.
现在,如果您运行composer -V意味着您将获得输出,Composer Version然后是版本号。
Hope this will help someone.
希望这会帮助某人。
回答by Tahir Yasin
Simply run this command for installing composer globally
只需运行此命令即可全局安装 composer
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
回答by LeoSarli
Just move it to /usr/local/binfolder and remove the extension
只需将其移动到/usr/local/bin文件夹并删除扩展名
sudo mv composer.phar /usr/local/bin/composer
回答by Tadej
For MAC and LINUX use the following procedure:
对于 MAC 和 LINUX,请使用以下步骤:
Add the directory where composer.phar is located to you PATH:
将 composer.phar 所在的目录添加到您的 PATH 中:
export PATH=$PATH:/yourdirectory
and then rename composer.phar to composer:
然后将 composer.phar 重命名为 composer:
mv composer.phar composer
回答by Muhammad Raihan Muhaimin
For running it from other location you can use the composer program that come with the program. It is basically a bash script. If you don't have it you can create one by simply copying the following code into a text file
要从其他位置运行它,您可以使用该程序附带的 Composer 程序。它基本上是一个 bash 脚本。如果您没有它,您可以通过简单地将以下代码复制到文本文件中来创建一个
#!/bin/sh
dir=$(d=$(dirname "curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
"); cd "$d" && pwd)
if command -v 'cygpath' >/dev/null 2>&1; then
dir=$(cygpath -m $dir);
fi
dir=$(echo $dir | sed 's/ /\ /g')
php "${dir}/composer.phar" $*
Then save the file inside your bin folder and name it composer without any file extension. Then add the bin folder to your environment variable f
然后将文件保存在 bin 文件夹中,并将其命名为 Composer,不带任何文件扩展名。然后将 bin 文件夹添加到您的环境变量 f
回答by user3257693
You can do a simple global install to run it from anywhere
您可以进行简单的全局安装以从任何地方运行它
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi
The https://getcomposer.org/doc/00-intro.md#globallywebsite recommends this way. Worked well on Ubuntu 14.04 no problem.
This way you don't need to do as an example php compomser.phar show, you just do composer show, in any directory you are working with.
该https://getcomposer.org/doc/00-intro.md#globally网站建议使用此方法。在 Ubuntu 14.04 上运行良好没问题。这样你就不需要做例子php compomser.phar show,你只需要composer show在你正在使用的任何目录中做。
回答by karolus
Some of this may be due to the OS your server is running. I recently did a migration to a new hosting environment running Ubuntu. Adding this alias alias composer="/path/to/your/composer"to .bashrc or .bash_aliases didn't work at first because of two reasons:
其中一些可能是由于您的服务器正在运行的操作系统。我最近迁移到运行 Ubuntu 的新托管环境。alias composer="/path/to/your/composer"由于两个原因,将此别名添加到 .bashrc 或 .bash_aliases 起初不起作用:
The server was running csh, not bash, by default. To check if this is an issue in your case, run echo $0. If the what is returned is -cshyou will want to change it to bash, since some processes run by Composer will fail using csh/tcsh.
默认情况下,服务器运行的是 csh,而不是 bash。要检查这是否是您的问题,请运行echo $0. 如果返回的是-csh您想要将其更改为 bash,因为 Composer 运行的某些进程将使用 csh/tcsh 失败。
To change it, first check if bash is available on your server by running cat /etc/shells. If, in the list returned, you see bin/bash, you can change the default to bash by running chsh -s /bin/csh.
要更改它,首先检查 bash 在您的服务器上是否可用,运行cat /etc/shells. 如果在返回的列表中看到bin/bash,则可以通过运行 将默认值更改为 bash chsh -s /bin/csh。
Now, at this point, you should be able to run Composer, but normally, on Ubuntu, you will have to load the script at every session by sourcing your Bash scripts by running source ~/.bashrcor source ~/.bash_profile. This is because, in most cases, Ubuntu won't load your Bash script, since it loads .profileas the default script.
现在,此时,您应该能够运行 Composer,但通常情况下,在 Ubuntu 上,您必须通过运行source ~/.bashrc或来获取 Bash 脚本,从而在每个会话中加载脚本source ~/.bash_profile。这是因为,在大多数情况下,Ubuntu 不会加载您的 Bash 脚本,因为它.profile是作为默认脚本加载的。
To load your Bash scripts when you open a session, try adding this to your .profile (this is if your Bash script is .bashrc—modify accordingly if .bash_profile or other):
要在打开会话时加载您的 Bash 脚本,请尝试将其添加到您的 .profile(如果您的 Bash 脚本是 .bashrc,请相应地修改 .bash_profile 或其他):
##代码##To test, close your session and reload. If it's working properly, running composer -vor which composershould behave as expected.
要进行测试,请关闭会话并重新加载。如果它工作正常,运行composer -v或which composer应该按预期运行。

