macosx-10.11 - Mac OS X内置PHP如何扩展'pcntl'

 Z-ji 发布于 2022-11-20 03:00

最近公司需要搭建Phabricator服务,用到了LAMP套件,其中在配置PHP时,需要扩展'pcntl'使用多进程,但在扩展时遇到了麻烦:

系统:
Mac OSX EI Capitan

PHP版本信息:(Mac OSX自带)
PHP 5.5.27 (cli) (built: Aug 22 2015 18:20:44)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies

具体情况如下:
使用 cpoptdeiMac:phabricator cpopt$ ./bin/phd start命令,终端提示

ERROR: The PHP extension 'pcntl' is not installed. You must install it to run daemons on this machine.

网上的安装'pcntl'基本上都是下面的方法:

首先下载一个php-5.4.24源代码包
进入源代码目录的 ext/pcntl/
cd /path/to/phpsrc/ext/pcnt/
phpize
make
sudo
make install
最后记得要修改系统php的php.ini,加载pcntl.so模块

我尝试了上面的方法,重新下载了一个对应版本的PHP安装包,执行上面的命令,但一直报下面的错误:

cpoptdeiMac:pcntl cpopt$ pwd
/Users/cpopt/Downloads/php-5.5.27/ext/pcntl
cpoptdeiMac:pcntl cpopt$ phpize
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:  
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.

cpoptdeiMac:pcntl cpopt$ 

于是我又Google了半天,找到这个问题的解决方案如下,但是也是出错,提示非法操作

cpopt$ sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include

目前为止,已经耗了一天时间了还没有解决,希望大家能够帮助我渡过难关!谢谢!

2 个回答
  • 哥们解决了吗?? 我在MAC下也遇到了同样的问题

    2022-11-20 03:03 回答
  • 我也有类似的报错:

        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:
    

    最后在stackoverflow 上找到一个类似的问题

    • xcode-select —install 先安装 xcode命令行工具就可以了,原因暂时不知

    • ./configure

    • sudo make

    • sudo make install
      最后出现错误(移动so文件出问题)

             Installing shared extensions:     /usr/lib/php/extensions/no-debug-non-zts-20121212/
             cp: /usr/lib/php/extensions/no-debug-non-zts-20121212/#INST@5555#: Operation not permitted
             make: *** [install-modules] Error 1
      
      就是sudo自己移动也出问题  
      
             cp: /usr/lib/php/extensions/no-debug-non-zts-20121212/pcntl.so: Operation not permitted
      
    • 默认的php扩展库的位置不能移动进去,就移动自己建的目录中,之后再配置设置自己的文件目录就行了

      `sudo mkdir /usr/local/my-php-ext`  
      `sudo cp ./modules/pcntl.so /usr/local/my-php-ext/pcntl.so`   (编译好的pcntl文件在./modules 中)
      
    • sudo echo 'extension=/usr/local/my-php-ext/pcntl.so' >> /etc/php.ini

    • sudo apachectl restart 重启apache

    • 查看是否安装成功

         $ php -ini | grep pcntl
         pcntl
         pcntl support => enabled
         PWD => /Users/andyron/myfield/www/test/php-src-php-5.5.34/ext/pcntl
         _SERVER["PWD"] => /Users/andyron/myfield/www/test/php-src-php-5.5.34/ext/pcntl
    2022-11-20 03:03 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有