Mac使用pecl安装grpc报错:Warning:mkdir():File exists in System.php

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]

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章