如何覆盖PHP的路径以使用MAMP路径? [英] How to override the path of PHP to use the MAMP path?

查看:15
本文介绍了如何覆盖PHP的路径以使用MAMP路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试让 SOAP 模块正常工作(-bash:/usr/bin/php:没有这样的文件或目录)之后,我在 MAC 上完全搞砸了我的 PHP 配置....) 我现在必须使用 MAMP 但每次我必须输入路径

After screwing up entirely my PHP configuration on MAC trying to get the SOAP module working (-bash: /usr/bin/php: No such file or directory ....) I now have to use MAMP but each time I have to type the path

Applications/MAMP/bin/php5.3/bin/php to do command line.

如何只输入 php 而不是 MAC 上的整个路径? 我仔细检查过,我没有名为 .profile 的文件,也没有 bash_profile

How to just type php instead the entire path on MAC ? I double checked and i do not have a file named .profile nor bash_profile

谢谢

PS:这是输出 echo $PATH :

PS: Here's what output echo $PATH :

echo $PATH
/Applications/MAMP/Library/bin/:/Applications/MAMP/bin/php5/bin/:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/X11/bin

推荐答案

每次保存 MAMP 配置(PHP 部分)时,它都会在 ~/.profile 文件中保存当前版本的 PHP 并创建php、pear 和 pecl 的别名,指向当前配置的版本.(注意:您需要在 MAMP 中选中在命令行上提供此版本"选项)

Everytime you save MAMP config (PHP section), it saves the current version of PHP on ~/.profile file and creates the alias for php, pear and pecl, to point to the current configured version. (Note: you need to check "Make this version available on the command line" option in MAMP)

但是,您需要刷新终端(打开另一个会话)才能刷新此文件.您也可以输入 source ~/.profile 手动刷新别名.

However, you need to refresh your terminal (open another session) to get this file refreshed. You can also type source ~/.profile to refesh the aliases manually.

如果您想在 PHP_VERSION 变量中提取此当前版本 - 如上所述 - 以供进一步使用,您可以:

If you want to extract this curerent version in a PHP_VERSION variable - as commented above - for further use, you can do:

export PHP_VERSION=`grep "alias php" ~/.profile | cut -d"/" -f6 | cut -c4-`

然后您将获得 $PHP_VERSION 可用于当前版本的 MAMP.

And then you'll have $PHP_VERSION available with the current version of MAMP.

最后,如果您想在 mamp 上使用当前配置的版本运行您的 php,您只需要将以下内容添加到您的 ~/.bash_profile 中:

Finally, if you want to run your php using the current configured version on mamp, you just need to add to your ~/.bash_profile the following:

export PHP_VERSION=`grep "alias php" ~/.profile | cut -d"/" -f6 | cut -c4-`
export PHPRC="/Library/Application Support/appsolute/MAMP PRO/conf/" #point to your php.ini folder to use the same php settings
export PATH=/Applications/MAMP/bin/php/php$PHP_VERSION/bin:$PATH

现在,即使是依赖于 /usr/bin/env php 的脚本也会从 Mamp 配置中读取正确的版本.

Now, even script that relies on /usr/bin/env php will read the correct version from Mamp config.

这篇关于如何覆盖PHP的路径以使用MAMP路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆