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

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

问题描述

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

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

server:trackstar charlieryan$ protected/yiic shell

Yii 交互工具 v1.1(基于 Yii v1.1.13)请输入帮助"寻求帮助.输入exit"退出.

<块引用><块引用>

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

据我所知,这是因为使用的是 Mac OS X 自己的 PHP 版本,它不支持 MySQL PDO 驱动程序,但 MAMP 自己的版本支持.

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

解决方案

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

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

vi ~/.profile# 如果有一个 PATH=... 行,在所有其他人的前面添加 mamp 路径PATH=/Applications/MAMP/bin:/existing/paths/if/any:$PATH

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

source ~/.profile

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

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.

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 Interactive Tool v1.1 (based on Yii v1.1.13) Please type 'help' for help. Type 'exit' to quit.

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:

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.

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?

解决方案

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?

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

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天全站免登陆