秋枫阁,秋枫阁-科技馆,Blog,博客,个人博客,Maple,Zoe,Maple与Zoe

Mac电脑安装PHP扩展

  • 作者:Maple
  • 时间:2019-02-27 15:48:06
  • 4462人已阅读
分享  PHP 
简介Mac HomeBrew 自 2018-03-31 起弃用 homebrew/php 后,导致扩展都不可以用 brew install php71-XXX的方式安装,但是PHP还可以安装,如 brew install php@7.1 。不过现在可以使用 pecl 安装扩展,由于我的开发环境需要用到 redis、MongoDB、event扩展,下面讲这几个扩展安装的具体操作。

1. 安装 homebrew

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

2. 安装 PHP7.1

brew install php@7.1

若想安装最新版则使用

brew install php

3. 添加php@7.1到 PATH 中

echo 'export PATH="/usr/local/opt/php@7.1/bin:$PATH"' >> ~/.bash_profile
echo 'export PATH="/usr/local/opt/php@7.1/sbin:$PATH"' >> ~/.bash_profile

记得刷新环境变量哦

source ~/.bash_profile

4. 安装 igbinary 扩展

pecl install igbinary

出现 Extension igbinary enabled in php.ini 表示安装成功,否则安装失败。

5. 安装 redis 扩展

pecl install redis

注意选项

enable igbinary serializer support? [no] : yes
enable lzf compression support? [no] : no

出现 Extension redis enabled in php.ini 表示安装成功,否则安装失败。

6. 安装 MongoDB 扩展

pecl install mongodb

出现 Extension mongodb enabled in php.ini 表示安装成功,否则安装失败。

7. 安装 event 扩展

pecl install event

注意:执行此命令后,会提示你输入各个选项的值,其他的都可以默认,遇到下列选项时根据你的实际情况填写

Enable internal debugging in Event [no] :
Enable sockets support in Event [yes] :
libevent installation prefix [/usr] : /usr/local/Cellar/libevent/2.1.8(按照你的实际路径填写)
Include libevent's pthreads library and enable thread safety support in Event [no] :
Include libevent protocol-specific functionality support including HTTP, DNS, and RPC [yes] :
Include libevent OpenSSL support [yes] :
PHP Namespace for all Event classes [no] :
openssl installation prefix [no] : /usr/local/Cellar/openssl/1.0.2q(按照你的实际路径填写)

出现 Extension event enabled in php.ini 表示安装成功,否则安装失败。

8. 启动 PHP7.1

我的电脑安装了三个版本 7.1  7.2  7.3

对应启动命令分别为 php@7.1  php@7.2  php

启动:

brew services start php@7.1

重启:

brew services restart php@7.1

停止:

brew services stop php@7.1

9. 查看 PHP 扩展

php -m
Top