开发时,偶然需要安装php额外扩展,于是使用phpize,结果error,执行phpize -v一看,额>_<
grep: /usr/include/php/main/php.h: No such file or directory
grep: /usr/include/php/Zend/zend_modules.h: No such file or directory
grep: /usr/include/php/Zend/zend_extensions.h: No such file or directory
Configuring for:
PHP Api Version:
Zend Module Api No:
Zend Extension Api No:
在mac高版本/usr/include不存在了,所以这里报错。于是在网上搜索解决方案,于是漫长的“黑科技”操作开始了,就是用各种方法生成这个目录。而遗憾的是:我的mac版本是当前最新的11.2.3版本,所有这些骚操作全部无效,顿时汗了。
苹果系统干掉/usr/include肯定是有原因的,肯定存在另外一种方法解决这个问题。为什么要花这么多心思,这么头铁地跟系统较劲,一定要创建出这个/usr/includ?
本人使用的是php7.3,通过brew安装。仔细观察命令行,直接调用phpize是使用的/usr/bin中的phpize,而通过brew安装的php的命令位于/usr/local/Cellar/php@7.3/7.3.27/bin中,那么尝试改用它的命令执行:/usr/local/Cellar/php@7.3/7.3.27/bin/phpize -v
Configuring for:
PHP Api Version: 20180731
Zend Module Api No: 20180731
Zend Extension Api No: 320180731
运行通过,看来,MAC安装扩展需要指明php安装的真实位置,使用默认的很可能就会因为没有/usr/include目录而报错。那么对应mac,安装扩展的正确命令应该如下(以brew安装的php@7.3为例):
/usr/local/Cellar/php@7.3/7.3.27/bin/phpize
./configure --with-php-config=/usr/local/Cellar/php@7.3/7.3.27/bin/php-config
make
make install
完成后,记得php.ini加入扩展配置(extension=xxxx.so),并重启php-fpm让扩展生效。