使用终端,如何使OS X使用MAMPs版本的PHP [英] Using terminal, how do I make OS X use MAMPs version of PHP

查看:57
本文介绍了使用终端,如何使OS X使用MAMPs版本的PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在学习Yii框架,昨天运行的其中一部教程要求我测试项目的数据库连接.

I'm currently learning the Yii framework, and one of the tutorials I was running through yesterday required me to test the database connection of a project.

这里的细节不是很重要,但是基本上,当我运行shell并键入命令时,它会引发如下错误:

The details aren't too important here, but basically when I run shell, and type in the command it throws up an error as follows:

server:trackstar charlieryan$ protected/yiic shell

Yii互动工具v1.1(基于Yii v1.1.13) 请输入帮助"以获取帮助.键入退出"退出.

Yii Interactive Tool v1.1 (based on Yii v1.1.13) Please type 'help' for help. Type 'exit' to quit.

回声Yii :: app()-> db-> connectionString; PHP警告:PDO :: __ construct():[2002]/Applications/MAMP/htdocs/trackstar/yii/framework/中没有这样的文件或目录(试图通过unix:///var/mysql/mysql.sock连接)第423行的db/CDbConnection.php /Applications/MAMP/htdocs/trackstar/yii/framework/db/CDbConnection.php:381中的异常"CDbException",消息为"CDbConnection无法打开数据库连接:SQLSTATE [HY000] [2002]没有这样的文件或目录" 堆栈跟踪:

echo Yii::app()->db->connectionString; PHP Warning: PDO::__construct(): [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) in /Applications/MAMP/htdocs/trackstar/yii/framework/db/CDbConnection.php on line 423 exception 'CDbException' with message 'CDbConnection failed to open the DB connection: SQLSTATE[HY000] [2002] No such file or directory' in /Applications/MAMP/htdocs/trackstar/yii/framework/db/CDbConnection.php:381 Stack trace:

据我了解,这是因为正在使用Mac OS X自己的PHP版本,该版本不支持MySQL PDO驱动程序,而MAMP自己的版本却支持.

As far as I understand this is because Mac OS X's own version of PHP is being used which does not have support for a MySQL PDO Driver, but MAMP's own version does.

当我执行哪个php"命令时,它返回"/usr/bin/php",这是不正确的版本.如何将其更改为默认的MAMP版本?

When I do the "which php" command, it returns "/usr/bin/php", which is the incorrect version. How do I change this to default to the MAMP version?

推荐答案

当我执行哪个php"命令时,它返回"/usr/bin/php",这是不正确的版本.如何将其更改为默认的MAMP版本?

When I do the "which php" command, it returns "/usr/bin/php", which is the incorrect version. How do I change this to default to the MAMP version?

您需要将MAMP版本添加到您的路径或使用完整路径来调用它.我不确定MAMP的php二进制文件在哪里,但可以说它在/Applications/MAMP/bin中.因此,在这种情况下,您需要将该路径添加到您的.profile:

You need to add the MAMP version to your path or invoke it with the full path. Im not sure where MAMP's php binary lives but lets say its in /Applications/MAMP/bin. So in that case youll need to add that path to your .profile:

vi ~/.profile
# if there is a PATH=... line add the mamp path in front of all the others
PATH=/Applications/MAMP/bin:/existing/paths/if/any:$PATH

然后关闭终端或运行命令:

then either close terminal or run the command:

source ~/.profile

这将重新加载您的个人资料.现在,如果您执行which php,它将首先找到MAMP版本.同样,我不知道那是MAMP bin目录的正确路径,因此您需要验证并使用正确的路径.

This will reload your profile. Now if you do which php it should find the MAMP version first. Again, I dont know that that is the correct path for the MAMP bin dir, so you need to verify that and use the correct one.

这篇关于使用终端,如何使OS X使用MAMPs版本的PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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