为Mac OS X 中的MAMP安装 libmosquitto PHP扩展

港控/mmm° 2022-01-13 07:21 297阅读 0赞

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

进入MAMP的目录,选择要安装libmosquitto扩展的PHP版本,比如:

cd /Applications/MAMP/bin/php/php5.3.29/bin

然后使用 ./pecl install mosquitto-beta

*注:默认使用./pecl install mosquitto,即可查看当前mosquitto的哪个版本是最新的stable版本。例如:

  1. ./pecl install mosquitto
  2. Failed to download pecl/mosquitto within preferred state "stable", latest release is version 0.3.0, stability "beta", use "channel://pecl.php.net/mosquitto-0.3.0" to install

安装顺利的话,会生成mosquitto.so在 /Applications/MAMP/bin/php/php5.3.29/lib/php/extensions/no-debug-non-zts-20090626 中。然后在php.ini中加入

  1. extension=mosquitto.so

重启httpd即可。

但我在安装的时候出现了一些状况,特列出如下,以便大家借鉴:

1. autoconf 不存在

  1. ./pecl install mosquitto-beta
  2. downloading Mosquitto-0.3.0.tgz ...
  3. Starting to download Mosquitto-0.3.0.tgz (25,395 bytes)
  4. .........done: 25,395 bytes
  5. 5 source files, building
  6. running: phpize
  7. grep: /Applications/MAMP/bin/php/php5.3.29/include/php/main/php.h: No such file or directory
  8. grep: /Applications/MAMP/bin/php/php5.3.29/include/php/Zend/zend_modules.h: No such file or directory
  9. grep: /Applications/MAMP/bin/php/php5.3.29/include/php/Zend/zend_extensions.h: No such file or directory
  10. Configuring for:
  11. PHP Api Version:
  12. Zend Module Api No:
  13. Zend Extension Api No:
  14. Cannot find autoconf. Please check your autoconf installation and the
  15. $PHP_AUTOCONF environment variable. Then, rerun this script.
  16. ERROR: `phpize' failed

由于我安装了home brew , 所以直接 brew install autoconf 就成功的解决了这个问题。

2. 找不到 php.h 等头文件

上面日志也包含了phpize运行的错误:

  1. running: phpize
  2. grep: /Applications/MAMP/bin/php/php5.3.29/include/php/main/php.h: No such file or directory
  3. grep: /Applications/MAMP/bin/php/php5.3.29/include/php/Zend/zend_modules.h: No such file or directory
  4. grep: /Applications/MAMP/bin/php/php5.3.29/include/php/Zend/zend_extensions.h: No such file or directory

这个问题是由于 PECL 没有在当前MAMP的php版本目录中的include目前下找到对应的php头文件。解决这个问题的前提是安装了XCode,Xcode的SDK里面包含了PHP的相关头文件,所以可以进入到php5.3.29目录下,创建一个软链接,指向Xcode的PHP SDK。

  1. cd /Applications/MAMP/bin/php/php5.3.29
  2. ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/ include

然后重新执行pecl install mosquitto-beta就安装成功了。

转载于:https://my.oschina.net/fangyisheng/blog/717336

发表评论

表情:
评论列表 (有 0 条评论,297人围观)

还没有评论,来说两句吧...

相关阅读