美文网首页
PHP安装mongodb扩展

PHP安装mongodb扩展

作者: _零 | 来源:发表于2018-09-12 13:01 被阅读0次

    以下提供一种安装PHP mongodb扩展的方式 pecl

    网上说不推荐使用pecl安装PHP扩展

    原文链接
    https://my.oschina.net/lwl1989/blog/1924896

    但是当你使用brew ,wget方式安装都失败的时候,还一直找不到解决的办法,可以试一试pecl安装

    首先macOS上安装pecl

    继续附上原文链接
    http://www.mayanlong.com/archives/2018/pear.html

    为防止链接失效,方便阅读,在下面继续写一份

    简介

    PECL(The PHP Extension Community Library)是 PHP 扩展的存储库,为 PHP 所有的扩展提供提供托管和下载服务。
    通过 PEAR(PHP Extension and Application Repository)的 Package Manager 的安装管理方式,可以对 PECL 扩展进行下载和安装。

    安装

    官方提供了 PEAR 在各个平台的安装方式,直接看官方文档的请进【传送门】,macOS 平台官方安装翻译如下。

    1.下载PEAR

    使用 curl 命令下载即可:

    $ curl -O https://pear.php.net/go-pear.phar
    
    2.安装PEAR

    使用 sudo 授权进行安装:

    $ sudo php -d detect_unicode=0 go-pear.phar
    

    安装过程需要进行简单的配置,如下:

    Below is a suggested file layout for your new PEAR installation.  To
    change individual locations, type the number in front of the
    directory.  Type 'all' to change all of them or simply press Enter to
    accept these locations.
    
     1. Installation base ($prefix)                   : /usr
     2. Temporary directory for processing            : /tmp/pear/install
     3. Temporary directory for downloads             : /tmp/pear/install
     4. Binaries directory                            : /usr/bin
     5. PHP code directory ($php_dir)                 : /usr/share/pear
     6. Documentation directory                       : /usr/docs
     7. Data directory                                : /usr/data
     8. User-modifiable configuration files directory : /usr/cfg
     9. Public Web Files directory                    : /usr/www
    10. System manual pages directory                 : /usr/man
    11. Tests directory                               : /usr/tests
    12. Name of configuration file                    : /private/etc/pear.conf
    
    1-12, 'all' or Enter to continue: 1
    

    输入 1,将安装根目录修改为 /usr/local/pear;
    输入 4,将命令安装到 /usr/local/bin 目录;
    其它选项默认即可,一路回车。

    3.检查安装是否成功

    出现如下结果,则安装成功:

    $ pear version
    PEAR Version: 1.10.5
    PHP Version: 7.1.7
    Zend Engine Version: 3.1.0
    

    安装mongodb扩展

    找到pecl位置

    $ find / -name pecl
    

    我的位置是

    /usr/local/bin/pecl
    

    安装mongodb

    $ sudo /usr/local/bin/pecl install mongodb
    

    安装成功之后,会有mongdb.so扩展

    Build process completed successfully
    Installing '/usr/lib/php/extensions/no-debug-non-zts-20131226/mongodb.so'
    install ok: channel://pecl.php.net/mongodb-1.5.2
    configuration option "php_ini" is not set to php.ini location
    You should add "extension=mongodb.so" to php.ini
    

    去检查一下扩展下载成功了没有

    $ ls /usr/lib/php/extensions/no-debug-non-zts-20131226/
    

    发现有mongodb.so,去php.ini文件中添加扩展

    $ sudo vim /etc/php.ini
    

    在php.ini文件中添加

    extension=mongodb.so
    

    扩展安装成功,重启一下php-fpm
    查看有没有mongodb扩展

    $ php -m | grep mongodb
    

    相关文章

      网友评论

          本文标题:PHP安装mongodb扩展

          本文链接:https://www.haomeiwen.com/subject/vsdvgftx.html