之前爬了一大堆数据存放在mongodb上,这几天正好在研究typecho,所以打算在typecho上新建一个页面模版,然后调用相关数据。
▌过程
最开始是通过百度看教程来安装,发现不大对劲,于是直接上官网看教程:MongoDB PHP Driver
▌方法一:
sudo pecl install mongodb
extension=mongodb.so
错误信息
WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update
Warning: popen() has been disabled for security reasons in OS/Guess.php on line 241
PHP Warning: popen() has been disabled for security reasons in /www/server/php/73/lib/php/OS/Guess.php on line 241
Warning: popen() has been disabled for security reasons in /www/server/php/73/lib/php/OS/Guess.php on line 241
Warning: fgets() expects parameter 1 to be resource, null given in OS/Guess.php on line 242
PHP Warning: fgets() expects parameter 1 to be resource, null given in /www/server/php/73/lib/php/OS/Guess.php on line 242
Warning: fgets() expects parameter 1 to be resource, null given in /www/server/php/73/lib/php/OS/Guess.php on line 242
Warning: pclose() expects parameter 1 to be resource, null given in OS/Guess.php on line 251
PHP Warning: pclose() expects parameter 1 to be resource, null given in /www/server/php/73/lib/php/OS/Guess.php on line 251
Warning: pclose() expects parameter 1 to be resource, null given in /www/server/php/73/lib/php/OS/Guess.php on line 251
downloading mongodb-1.6.1.tgz ...
Starting to download mongodb-1.6.1.tgz (1,094,379 bytes)
.........................................................................................................................................................................................................................done: 1,094,379 bytes
434 source files, building
Warning: putenv() has been disabled for security reasons in PEAR/Builder.php on line 311
PHP Warning: putenv() has been disabled for security reasons in /www/server/php/73/lib/php/PEAR/Builder.php on line 311
Warning: putenv() has been disabled for security reasons in /www/server/php/73/lib/php/PEAR/Builder.php on line 311
running: phpize
Warning: popen() has been disabled for security reasons in PEAR/Builder.php on line 467
PHP Warning: popen() has been disabled for security reasons in /www/server/php/73/lib/php/PEAR/Builder.php on line 467
Warning: popen() has been disabled for security reasons in /www/server/php/73/lib/php/PEAR/Builder.php on line 467
ERROR: failed to run `phpize'
▌方法二(官方推荐安装方法):
composer require mongodb/mongodb
错误信息
Warning: putenv() has been disabled for security reasons in phar:///usr/bin/composer/bin/composer on line 50
Warning: This development build of composer is over 60 days old. It is recommended to update it by running "/usr/bin/composer self-update" to get the latest version.
Using version ^1.5 for mongodb/mongodb
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
PHP Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in phar:///usr/bin/composer/src/Composer/DependencyResolver/RuleSetGenerator.php on line 286
Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in phar:///usr/bin/composer/src/Composer/DependencyResolver/RuleSetGenerator.php on line 286
Your requirements could not be resolved to an installable set of packages.
Problem 1
- mongodb/mongodb 1.5.1 requires ext-mongodb ^1.6 -> the requested PHP extension mongodb is missing from your system.
- mongodb/mongodb 1.5.0 requires ext-mongodb ^1.6 -> the requested PHP extension mongodb is missing from your system.
- Installation request for mongodb/mongodb ^1.5 -> satisfiable by mongodb/mongodb[1.5.0, 1.5.1].
To enable extensions, verify that they are enabled in your .ini files:
- /www/server/php/73/etc/php.ini
You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.
Installation failed, deleting ./composer.json.
▌安装成功
最后还是通过github的大婶才安装成功。
方法一:不过这个方法安装的版本并不是最新的
sudo apt-get install php-mongodb
sudo phpenmod mongodb
方法二:使用pecl安装最新版本
//安装pecl
sudo apt install php-pear
sudo apt install php-dev
//通过pecl安装mongodb
sudo pecl install mongodb
//添加extension 到 php
sudo phpenmod mongodb