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擴展了)
 
若有錯誤請你們指出!
相關文章
相關標籤/搜索