将 PHP 路径更改为 MAMPs PHP
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10857068/
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
change the PHP path to MAMPs PHP
提问by Johannes Klau?
I'm running PHP with MAMP on OSX 10.5.8
我在 OSX 10.5.8 上使用 MAMP 运行 PHP
So if I want to run a script from console I always need to write
所以如果我想从控制台运行脚本,我总是需要写
/applications/mamp/bin/php5.3/bin/php path/to/script
which is annoying. Is there a way to change the default path to php so that I can write
这很烦人。有没有办法改变php的默认路径,这样我就可以写了
php path/to/script
and still uses MAMPs PHP version?
仍然使用 MAMPs PHP 版本?
回答by bfavaretto
Create a file called .bash_profileon your home directory (if you don't have this file already), and add this to the file:
创建一个.bash_profile在您的主目录中调用的文件(如果您还没有此文件),并将其添加到文件中:
export PATH=/Applications/mamp/bin/php5.3/bin:$PATH
Then quit and relaunch Terminal.app
然后退出并重新启动 Terminal.app
回答by Amrit Shrestha
Use latest MAMP version of PHP
使用最新的 MAMP 版本的 PHP
you need to edit .bash_profile
你需要编辑 .bash_profile
open -a TextEdit ~/.bash_profile
if you cannot find bash_profile under your home directory then create .bash_profile:
如果在您的主目录下找不到 bash_profile,则创建 .bash_profile:
touch ~/.bash_profile
Use latest MAMP version of PHP
使用最新的 MAMP 版本的 PHP
PHP_VERSION=`ls /Applications/MAMP/bin/php/ | sort -n | tail -1`
export PATH=/Applications/MAMP/bin/php/${PHP_VERSION}/bin:$PATH
(Use source ~/.bash_profile after making your changes to make sure they take effect.)
(在进行更改后使用 source ~/.bash_profile 以确保它们生效。)
source: How to override the path of PHP to use the MAMP path?
回答by kjellberg
The easiest way would be to rewrite the alias. Just copy/paste the cmd bellow into terminal for temporary use or write it into .bash_profile to make it permanent.
最简单的方法是重写别名。只需将下面的 cmd 复制/粘贴到终端中以供临时使用或将其写入 .bash_profile 以使其永久化。
For MAMP
对于 MAMP
$ alias php=/applications/mamp/bin/php5.3/bin/php
For XAMPP
对于 XAMPP
$?alias php=/Applications/XAMPP/bin/php
For AMPPS
对于 AMPPS
$?alias php=/Applications/AMPPS/php-5.6/bin/php
Run php via our new alias
通过我们的新别名运行 php
$?php -v
回答by Hyman Sun
vi ~/.bash_profile
//add
export PATH=/path/to/php/bin:$PATH
source ~/.bash_profile
回答by Henu
In addition to bfvarettos great answer: since .bash_profile executes at login, you will need to restart your system for the changes to take effect.
除了 bfvarettos 很好的答案:由于 .bash_profile 在登录时执行,您需要重新启动系统以使更改生效。
回答by travisneids
I'm not sure if this is specific to MAMP 3.0 or not but you need to do the following path for MAMP 3.0. Make sure you change the PHP version to the version you are using for your server.
我不确定这是否特定于 MAMP 3.0,但您需要为 MAMP 3.0 执行以下路径。确保将 PHP 版本更改为用于服务器的版本。
Again this goes in ~/.bash_profile
这再次进入 ~/.bash_profile
export PATH=/Applications/MAMP/bin/php/php5.5.10/bin:$PATH

