安装 MongoDB PHP 驱动 在CentOS 6.x和遇到的问题

时间:2021-06-04 00:04:35

以下安装mongo-php-driver 也许会遇到

PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/mongodb.so' - /usr/lib64/php/modules/mongodb.so: undefined symbol: bson_decimal128_from_string in Unknown on line 0

问题。

[root@www mongo-php-driver]# git clone https://github.com/mongodb/mongo-php-driver          


Initialized empty Git repository in /home/.../mongo-php-driver/.git/

remote: Counting objects: 9821, done.

remote: Compressing objects: 100% (10/10), done.

remote: Total 9821 (delta 2), reused 0 (delta 0), pack-reused 9811

Receiving objects: 100% (9821/9821), 3.25 MiB | 642 KiB/s, done.


Resolving deltas: 100% (6883/6883), done.


[root@www mongo-php-driver]# cd mongo-php-driver                    

[root@www mongo-php-driver]# phpize                                        


遇到如下问题:

Configuring for:

PHP Api Version:         20131106

Zend Module Api No:      20131226

Zend Extension Api No:   220131226

/usr/bin/m4:config.m4:482: cannot open `src/libmongoc/build/autotools/WeakSymbols.m4': No such file or directory

/usr/bin/m4:config.m4:483: cannot open `src/libmongoc/build/autotools/m4/ax_pthread.m4': No such file or directory

/usr/bin/m4:config.m4:517: cannot open `src/libbson/build/autotools/CheckAtomics.m4': No such file or directory

/usr/bin/m4:config.m4:518: cannot open `src/libbson/build/autotools/FindDependencies.m4': No such file or directory

/usr/bin/m4:config.m4:519: cannot open `src/libbson/build/autotools/m4/ac_compile_check_sizeof.m4': No such file or directory

/usr/bin/m4:config.m4:520: cannot open `src/libbson/build/autotools/m4/ac_create_stdint_h.m4': No such file or directory

/usr/bin/m4:config.m4:565: cannot open `src/libmongoc/build/autotools/Versions.m4': No such file or directory

/usr/bin/m4:config.m4:579: cannot open `src/libbson/build/autotools/Versions.m4': No such file or directory


autom4te: /usr/bin/m4 failed with exit status: 1

解决问题使用如下:

[root@www mongo-php-driver]# git submodule update --init                    


参数 init前面是 ‘--’,两个半角减号,坑死自己了



Submodule 'src/libbson' (https://github.com/mongodb/libbson.git) registered for path 'src/libbson'

Submodule 'src/libmongoc' (https://github.com/mongodb/mongo-c-driver.git) registered for path 'src/libmongoc'

Initialized empty Git repository in /home/.../mongo-php-driver/src/libbson/.git/

remote: Counting objects: 9019, done.

remote: Compressing objects: 100% (4/4), done.

remote: Total 9019 (delta 0), reused 0 (delta 0), pack-reused 9015

Receiving objects: 100% (9019/9019), 6.32 MiB | 60 KiB/s, done.

Resolving deltas: 100% (6258/6258), done.

Submodule path 'src/libbson': checked out '82b3cb4d89fdb590cdda4d2bb591d0062ccc765e'

Initialized empty Git repository in /home/.../mongo-php-driver/src/libmongoc/.git/

remote: Counting objects: 26396, done.

remote: Compressing objects: 100% (147/147), done.

remote: Total 26396 (delta 79), reused 0 (delta 0), pack-reused 26249

Receiving objects: 100% (26396/26396), 14.34 MiB | 2.23 MiB/s, done.

Resolving deltas: 100% (19745/19745), done.


Submodule path 'src/libmongoc': checked out ‘62e680aa26754ef8dbdb2709aac4d2488507872a'


[root@www mongo-php-driver]# phpize                    


Configuring for:

PHP Api Version:         20131106

Zend Module Api No:      20131226

Zend Extension Api No:   220131226


[root@www mongo-php-driver]# ./configure                    


checking for grep that handles long lines and -e... /bin/grep

checking for egrep... /bin/grep -E

checking for a sed that does not truncate output... /bin/sed

..........

checking whether to build shared libraries... yes

checking whether to build static libraries... no

configure: creating ./config.status


mongodb was configured with the following options:


Build configuration:

  CFLAGS                                           : -g -O2

  Extra CFLAGS                                     :  -pthread 

  Developers flags (slow)                          : 

  Code Coverage flags (extra slow)                 : 

  System mongoc                                    : no

  System libbson                                   : no

  LDFLAGS                                          : 

  EXTRA_LDFLAGS                                    : 

  MONGODB_SHARED_LIBADD                            :  -lssl -lcrypto -lrt  


Please submit bugreports at:

  https://jira.mongodb.org/browse/PHPC

config.status: creating ./src/libmongoc/src/mongoc/mongoc-config.h

config.status: creating ./src/libmongoc/src/mongoc/mongoc-version.h

config.status: creating ./src/libbson/src/bson/bson-config.h

config.status: creating ./src/libbson/src/bson/bson-version.h

config.status: creating config.h


config.status: executing libtool commands


[root@www mongo-php-driver]# make                    

……

/bin/sh /home/markboo/mongo-php-driver/libtool --mode=install cp ./mongodb.la /home/.../mongo-php-driver/modules

libtool: install: cp ./.libs/mongodb.so /home/.../mongo-php-driver/modules/mongodb.so

libtool: install: cp ./.libs/mongodb.lai /home/.../mongo-php-driver/modules/mongodb.la

libtool: finish: PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/sbin" ldconfig -n /home/.../mongo-php-driver/modules

----------------------------------------------------------------------

Libraries have been installed in:

   /home/.../mongo-php-driver/modules


If you ever happen to want to link against installed libraries

in a given directory, LIBDIR, you must either use libtool, and

specify the full pathname of the library, or use the `-LLIBDIR'

flag during linking and do at least one of the following:

   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable

     during execution

   - add LIBDIR to the `LD_RUN_PATH' environment variable

     during linking

   - use the `-Wl,-rpath -Wl,LIBDIR' linker flag

   - have your system administrator add LIBDIR to `/etc/ld.so.conf'


See any operating system documentation about shared libraries for

more information, such as the ld(1) and ld.so(8) manual pages.

----------------------------------------------------------------------


Build complete.


Don't forget to run 'make test’.


[root@www mongo-php-driver]# make install                    

Installing shared extensions:     /usr/lib64/php/modules/

[root@www mongo-php-driver]# echo "extension=mongodb.so" > /etc/php.d/mongo.ini                    

[root@www mongo-php-driver]# cat /etc/php.d/mongo.ini                     

extension=mongodb.so


apache error_log里出现:

PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/mongodb.so' - /usr/lib64/php/modules/mongodb.so: undefined symbol: bson_decimal128_from_string in Unknown on line 0


这个c-driver的问题,mongo也还没暂时没有解决,链接如下:https://jira.mongodb.org/browse/CDRIVER-1173

描述如下:

Since bson_decimal128_from_string () requires a null terminated string, the BSON to JSON conversion for bson_decimal128_t allocates a new string+1 since the input isn't null terminated.

We should be able to avoid that extra malloc, either though stack allocation or passing the length to the bson_decimal128_from_string () function.


---------------------------------------------------------------------------------------

所以变更驱动,使用PECL驱动

# wget https://pecl.php.net/get/mongo-1.6.13.tgz                    

# tar zxvf mongo-1.6.13.tgz                    

# cd mongo-1.6.13                    

# phpize                    

# ./configure                    

# make                    

# make install                    

# echo "extension=mongo.so" > /etc/php.d/mongo.ini                    


# wget https://pecl.php.net/get/mongodb-1.1.6.tgz                    

# tar -xzf mongodb-1.1.6.tgz                    

# cd mongodb-1.1.6                    

# phpize                    

# ./configure                    

# make                    

# make install                    

# echo "extension=mongo.1.1.6.so" > /etc/php.d/mongodb.ini                    


# httpd -k restart                    


# php -i                     

mongo


MongoDB Support => enabled

Version => 1.6.13

Streams Support => enabled

SSL Support => enabled

                   Supported Authentication Mechanisms                   

MONGODB-CR => enabled

SCRAM-SHA-1 => enabled

MONGODB-X509 => enabled

GSSAPI (Kerberos) => disabled

PLAIN => disabled


Directive => Local Value => Master Value

mongo.allow_empty_keys => 0 => 0

mongo.chunk_size => 261120 => 261120

mongo.cmd => $ => $

mongo.default_host => localhost => localhost

mongo.default_port => 27017 => 27017

mongo.is_master_interval => 15 => 15

mongo.long_as_object => 0 => 0

mongo.native_long => 1 => 1

mongo.ping_interval => 5 => 5


mongodb


mongodb support => enabled

mongodb version => 1.1.6

mongodb stability => stable

libmongoc version => 1.3.5

libbson version => 1.3.5


Directive => Local Value => Master Value

mongodb.debug => no value => no value


后一种没有报错误,程序运行也没有问题!