Mac使用pecl安裝grpc報錯:Warning:mkdir():File exists in System.php on line 294
問題描述
Mac 使用 pecl 安裝PHP擴展 grpc, 報錯:
Warning: mkdir(): File exists in System.php on line 294
PHP Warning: mkdir(): File exists in /usr/local/Cellar/php/7.3.11/share/php/pear/System.php on line 294
Warning: mkdir(): File exists in /usr/local/Cellar/php/7.3.11/share/php/pear/System.php on line 294
ERROR: failed to mkdir /usr/local/Cellar/php/7.3.11/pecl/20180731
查看當前環境狀態
查看當前 PHP 版本:
$ php -v
PHP 7.3.11 (cli) (built: Oct 24 2019 11:29:00) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.11, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.3.11, Copyright (c) 1999-2018, by Zend Technologies
查看 php 命令位置:
$ which php
/usr/local/bin/php
$ ls -l /usr/local/bin/php
lrwxr-xr-x 1 wangtom admin 28 10 28 2019 /usr/local/bin/php -> ../Cellar/php/7.3.11/bin/php
可以看到 php 是通過 brew
安裝的,因爲 brew
安裝的庫都在 /usr/local/Cellar/
目錄下面。
執行安裝報錯:
$ sudo pecl install grpc
Starting to download grpc-1.29.1.tgz (3,382,883 bytes)
... (略) ...
Build process completed successfully
Installing '/usr/local/Cellar/php/7.3.11/pecl/20180731/grpc.so'
Warning: mkdir(): File exists in System.php on line 294
PHP Warning: mkdir(): File exists in /usr/local/Cellar/php/7.3.11/share/php/pear/System.php on line 294
Warning: mkdir(): File exists in /usr/local/Cellar/php/7.3.11/share/php/pear/System.php on line 294
ERROR: failed to mkdir /usr/local/Cellar/php/7.3.11/pecl/20180731
提示編譯成功,但是並未找到 grpc.so 文件。
網上一查,有一篇 《記一次mac安裝swoole的坑》中提供的方法竟然是 “解決方法:放棄。。。”。 哈哈。
另一篇《Mac 通過pecl安裝php擴展(swore)報錯》 提問中,韓天峯迴答“只是頭文件安裝失敗,不影響使用。”。
都不可以,自己再想想辦法吧。
解決辦法:
再次查看 Cellar/php/7.3.11/ 目錄:
$ ls -l /usr/local/Cellar/php/7.3.11/
total 176
-rw-r--r-- 1 wangtom staff 3140 10 28 2019 INSTALL_RECEIPT.json
-rw-r--r-- 1 wangtom staff 3204 10 22 2019 LICENSE
-rw-r--r-- 1 wangtom staff 72744 10 22 2019 NEWS
-rw-r--r-- 1 wangtom staff 1609 10 22 2019 README.md
drwxr-xr-x 12 wangtom staff 384 10 28 2019 bin
-rw-r--r-- 1 wangtom staff 628 10 28 2019 homebrew.mxcl.php.plist
drwxr-xr-x 3 wangtom staff 96 10 22 2019 include
drwxr-xr-x 4 wangtom staff 128 10 22 2019 lib
lrwxr-xr-x 1 wangtom staff 23 10 28 2019 pecl -> /usr/local/lib/php/pecl
drwxr-xr-x 3 wangtom staff 96 10 22 2019 sbin
drwxr-xr-x 4 wangtom staff 128 10 22 2019 share
既然程序自己創建目錄失敗,那我就提前幫他創建好,再重新執行是不是就好了?
開始提前創建 20180731/ 目錄:
$ sudo mkdir -p /usr/local/Cellar/php/7.3.11/pecl/20180731/
mkdir: /usr/local/Cellar/php/7.3.11/pecl/20180731/: Not a directory
但是報錯,目錄不存在,奇怪了。使用 ls -l
命令查看整個Cellar/php/7.3.11目錄:
$ cd /usr/local/Cellar/php/7.3.11
$ ls -l
total 176
-rw-r--r-- 1 wangtom staff 3.1K 10 28 2019 INSTALL_RECEIPT.json
-rw-r--r-- 1 wangtom staff 3.1K 10 22 2019 LICENSE
-rw-r--r-- 1 wangtom staff 71K 10 22 2019 NEWS
-rw-r--r-- 1 wangtom staff 1.6K 10 22 2019 README.md
drwxr-xr-x 12 wangtom staff 384B 10 28 2019 bin
-rw-r--r-- 1 wangtom staff 628B 10 28 2019 homebrew.mxcl.php.plist
drwxr-xr-x 3 wangtom staff 96B 10 22 2019 include
drwxr-xr-x 4 wangtom staff 128B 10 22 2019 lib
lrwxr-xr-x 1 wangtom staff 23B 10 28 2019 pecl -> /usr/local/lib/php/pecl
drwxr-xr-x 3 wangtom staff 96B 10 22 2019 sbin
drwxr-xr-x 4 wangtom staff 128B 10 22 2019 share
可以到 pecl 目錄是個軟連接。
/usr/local/Cellar/php/7.3.11/pecl 鏈接到了 /usr/local/lib/php/pecl 目錄
那就在 /usr/local/lib/php/pecl 目錄中創建 20180731 目錄,並賦給所有的執行權限,看看會不會成功。
$ mkdir -p /usr/local/lib/php/pecl/20180731
$ sudo chmod 777 /usr/local/lib/php/pecl/20180731
重新再執行 pecl install grpc
進行安裝:
$ sudo pecl install grpc
Starting to download grpc-1.29.1.tgz (3,382,883 bytes)
1565 source files, building
running: phpize
Configuring for:
PHP Api Version: 20180731
Zend Module Api No: 20180731
Zend Extension Api No: 320180731
... (略) ...
Build process completed successfully
Installing '/usr/local/Cellar/php/7.3.11/pecl/20180731/grpc.so'
install ok: channel://pecl.php.net/grpc-1.29.1
Extension grpc enabled in php.ini
這次成功了。
查看編譯的 grpc.so
文件,存在。
$ ls /usr/local/Cellar/php/7.3.11/pecl/20180731/
grpc.so
使用 php -m
命令查看 grpc 擴展是否安裝成功?
$ php -m |grep grpc
grpc
可以看到,擴展存在,安裝成功。
其他解決辦法:
(1) 源碼編譯安裝: 自己下載 PHP 的 grpc 擴展源碼,使用 phpize 編譯安裝。
(2) 可以換個 Linux 系統試試,推薦 Ubuntu。
後來又看到一篇 《PHP安裝擴展時拋出/usr/local/Cellar/[email protected]/7.1.25/pecl異常解決》,他是通過修改 php-config
,將 Cellar 目錄 pecl 改成別的目錄:
// 中的 『pecl』 換成 『lib』
// 修改前
extension_dir='/usr/local/Cellar/[email protected]/7.1.25/pecl/20160303'
// 修改後
extension_dir='/usr/local/Cellar/[email protected]/7.1.25/lib/php/20160303'
和本人解決方法類似,提示不能創建這個目錄,本人是強制讓給它創建好這個目錄,這個作者是換一個新目錄創建後重新編譯。
參考鏈接
https://www.php.net/manual/zh/install.pecl.phpize.php
http://www.botark.com/articles/19 (無效)
https://segmentfault.com/q/1010000019298398/a-1020000019400977 (無效)
https://www.cnblogs.com/liugx/p/11061670.html
[END]