如何重写PHP的路径以使用MAMP路径? [英] How to override the path of PHP to use the MAMP path?
问题描述
在将我的PHP配置完全搞乱之后,尝试使SOAP模块正常工作(-bash:/usr/bin/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.
如何直接在Mac上键入php而不是整个路径?我仔细检查了一下,但我没有名为.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-`
然后,您将在当前版本的MAMP中获得$ PHP_VERSION.
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屋!