# Mac切换自带的PHP为MAMP的PHP

**URL:** <https://www.shiqidu.com/t/topic/575>\
**Category:** 开发调优\
**Tags:** PHP\
**Created:** [2019 年4 月 9 日 03:20 UTC](https://www.shiqidu.com/t/topic/575 "2019-04-09T03:20:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

作者： ![Leon](https://www.shiqidu.com/user_avatar/www.shiqidu.com/leon/32/5_2.png) [@Leon](https://www.shiqidu.com/u/Leon)\
发布日期： [2019 年4 月 9 日 03:20 UTC](https://www.shiqidu.com/t/topic/575/1 "2019-04-09T03:20:44Z")

</div>

因为想要安装Yii3.0，所以需要PHP版本\>=7.2，在终端运行 `which php` 显示的是 `/usr/php/bin`，版本为7.1，不符合Yii3的最低PHP版本要求，所以需要使用MAMP的PHP代替系统的PHP。

因为我自带的shell是bash，所以需要修改的是bash\_profile文件

```shell
sudo vim ~/.bash_profile

```

打开后把MAMP的PHP的路径添加到PATH中。

```shell
export PATH=/Applications/MAMP/bin/php/php7.2.10/bin:$PATH:$GOBIN

```

![path](https://discourse.shiqidu.com/upload/discussion/20190409/7852d1b54d34a8a163f4d7dd445d975d_origin.png)

然后保存退出 `source .bash_profile` 使其生效。

再次执行`which php`

![which php](https://discourse.shiqidu.com/upload/discussion/20190409/0858ea8c79390772473d1d7855082736_origin.png)

**注意**

如果你安装了zsh，会出现重新打开terminal窗口时会发现php又跳回自带的PHP。

这是terminal init的时候并不会执行/.bash\_profile、/.bashrc等脚本了，这是因为其默认启动执行脚本变为了～/.zshrc。

所以解决办法输入 `vim ~/.zshrc`，在后面追加：

```auto
source ~/.bash_profile

```
