Mac homebrew-1.5之后安装php扩展的方法

 

1、之前Mac安装php及php扩展的方式php

用Mac的童鞋都知道,咱们之前都是用brew install php70,brew install php71 这样来安装php的,用brew install php70-xdebug,brew install php71-redis等这样来安装php某个版本对应的扩展的,并且这样的安装方式很是方便,每一个扩展都单独使用一个配置文件,放在/usr/local/etc/php/7.1/conf.d 里面(其中7.1是版本,你电脑上有多是其余版本),以下所示:linux

 bruce > … > php > 7.1 > conf.d > ls -l
total 56
-rw-r--r--  1 bruce  admin   300 Dec  2  2017 ext-igbinary.ini
-rw-r--r--  1 bruce  admin    62 Dec  4  2017 ext-imagick.ini
-rw-r--r--  1 bruce  admin  4132 Dec  2  2017 ext-memcached.ini
-rw-r--r--  1 bruce  admin    78 Apr  8 10:45 ext-opcache.ini
-rw-r--r--  1 bruce  admin   292 Dec  2  2017 ext-redis.ini
-rw-r--r--  1 bruce  admin   273 Apr 11 20:48 ext-xdebug.ini
 
2、第三方维护的php tap被移动到Homebrew/core

看,用brew search php71就有提示,我之前用的这个tap:josegonzalez/php 被移动到homebrew/core了redis

 bruce > ~ > brew search php71
==> Formulae
php@7.1 ✔
If you meant "php71" specifically:
It was migrated from josegonzalez/php to homebrew/core.

移动的缘由:homebrew在1.5版本更新时说明了将会在2018-03-31前弃用而且归档Homebrew/php这个tap,缘由是Homebrew组织已经没法经过非核心公式tap的方式,去维护一个可被使用者或贡献者接受的一致性的体验及持续完整性的工做量!segmentfault

什么鬼?我本身翻译的看了半天也以为不通顺啊,但大概意思我是知道的,本身看原文吧:swoole

https://brew.sh/2018/01/19/homebrew-1.5.0/php7

 By 31st March 2018 we will deprecate and archive the Homebrew/php tap. Unfortunately we have been unable to maintain an acceptable, consistent user or contributor experience and CI workload through non-core formula taps in the Homebrew organisation so we are continuing to migrate widely used formulae into Homebrew/core and encourage more niche formulae and options to be supported outside the Homebrew organisation.
 
We deprecated and archived the Homebrew/php tap and created new php and versioned php@* formulae in Homebrew/core. This completes the deprecation and archival of the last non-Homebrew/core tap for end-users. We encourage more niche formulae and options to be supported in taps outside the Homebrew organisation.
 
CI workload的CI是什么意思呢?

 

3、如今要怎么安装php以及php扩展?

 1)怎么安装php扩展app

首先我要说一下怎么安装扩展,由于发现这个问题就是由于我安装amqp扩展的时候,用brew search amqp,没法查询到相似php71-amqp这样的扩展,因而去网上搜索,发现好多人都说如今不能用brew的方式安装扩展了,要用 pecl install amqp这样的方式安装,因而就去查为何不能用brew的方式安装扩展了,查到的结果就是上面第二点提到的缘由,因而我就决定用pecl来安装amqp扩展,但是我历来没用过pecl,都不知道是什么,查了一下发现pecl是“PHP Extension Community Library”,翻译一下就是php扩展库,看pecl install amqp想到pecl确定是一个命令嘛,我电脑上没有就装一个呗,因而我就想去安装一个pecl,我先用brew查询一下有没有pecl:brew search pecl,结果查询到没有,并且出来一堆像报错同样的信息(认真看了一下其实不是报错),我就想brew怎么无法安装呢,难道要用源码包?因而去网上查,在 https://pecl.php.net/ 上才发现The packaging and distribution system used by PECL is shared with its sister,  PEAR. 为何是sister?不是brother?疑惑中。。。而后我又双叒叕去查pear是什么东西,我以为应该不会是我喜欢吃的雪梨,一查果真不是雪梨,而是“PHP Extension and Application Repository” 翻译一下就是PHP扩展及应用库,如今知道了PEAR是PECL的姐姐,但是我要安装的是PECL啊,到底要怎么安装???网上找了半天,跟这个兄弟同样没找着怎么安装pecl:
 
我要在个人系统中安装swoole扩展,官网提供的是用pecl方式安装,但是我输入pecl install swoole以后系统说没找到该命令,而后我百度了半天也没找到怎么在linux下安装pecl这个东西,请问这是个什么东东,如何安装他?
 
其实我如今已经知道,要使用pecl命令,只要安装pear就好了,可是查了半天,也没人说安装了pear就能使用pecl命令,后来看了好多答案都提到pear,我就准备安装个pear,因而brew search pear,靠,又没有,我查pear结果出来个“啥是B啊(shakespeare)”:
 bruce > ~ > brew search pear
==> Formulae
shakespeare

我想,难道又要用源码包安装?查啊查,度娘问完问谷姐,最后发现是这样装的:curl

由于我是Mac,因此在https://pear.php.net/manual/en/installation.getting.php 中搜索:Macide

curl -O https://pear.php.net/go-pear.phar
php -d detect_unicode=0 go-pear.phar
 
就是先下载,再用php安装,安装过程我也没记下来,反正应该没什么难度!
最后,终于安装好pear了,这样就可使用pecl了。

 

我只不过想安装个amqp扩展而已,结果折腾了半天,如今终于装好了,来吧,开始安装amqp扩展了:pecl install amqp ,擦,报错。。。我已经记不住是什么错误了,反正就是没法安装,我也不知道怎么解决!

 

最后我尝试 从新安装php:brew install php,安装完后,再用pecl install amqp,bingo,成功了!brew services restart php重启一php-fpm就能够在phpinfo里查到有这个扩展了!但我看了一下php.ini,发现果真像网上一个老外说的,It's very stupid that the pecl put the extension reference to the top of the php.ini,就是说pecl安装完php的扩展后,确实是会自动住php.ini添加一行启用扩展的语句,即extension=xxxx.so这种,可是这样太傻B了,居然直接添加到php.ini顶部去了,由于咱们都知道,这个语句应该放到php.ini中的这个区域:
;;;;;;;;;;;;;;;;;;;;;;
; Dynamic Extensions ;
;;;;;;;;;;;;;;;;;;;;;;
虽然不影响运行,可是总感受怪怪的!不过我仍是不去移动它,由于全部插件都是这么装的,每一个都移动一下太麻烦了,反正这样也能用!

 

也就是说若是要使用pecl安装扩展,须要从新安装php最新版,直接brew install php就能够了,之前用brew install php71,brew install php@71这样的方式安装过的,也能够用brew install php再次安装,不会覆盖原来版本的,可是好像会提示要覆盖什么东西,我安装的时候没记录下来,你们本身根据提示操做吧。

 

4、总结

总之,如今Mac安装php扩展的方式不能用brew了,找成用pecl安装了memcached

一、你须要用brew install php从新安装php(放心,不会覆盖之前的版本)
二、你须要安装pear(安装了pear就可使用pecl install xdebug这样的方式安装php扩展了)
 
若有错误请你们指出!
相关文章
相关标签/搜索