For Debian users: apt-get install php5-dev will install phpize for you.
インストール手順
MongoDB PHP ドライバは、ほぼすべてのシステムで動作します。 Windows、Mac OS X、Unix そして Linux。リトルエンディアンマシンおよびビッグエンディアンマシン。 32 ビットマシンおよび 64 ビットマシン。PHP 5.2、5.3、5.4 および 5.5。
この » PECL 拡張 モジュールは PHP にバンドルされていません。
手動インストール
ドライバの開発者や最新のバグフィックス版に興味のあるかたは、 » Github にある最新のソースコードからドライバをコンパイルすることもできます。 Github に行き、"download" ボタンをクリックしましょう。そして以下のようにします。
$ tar zxvf mongodb-mongodb-php-driver-<commit_id>.tar.gz $ cd mongodb-mongodb-php-driver-<commit_id> $ phpize $ ./configure $ make all $ sudo make install
php.ini を次のように変更します。
-
extension_dir 変数が mongo.so のあるディレクトリを指すようにします。 ビルド中に、PHP ドライバをどこにインストールするのかがこのように表示されます。
この場所が PHP の拡張モジュール用ディレクトリと一致するかどうかは、次のようにして確認します。Installing '/usr/lib/php/extensions/no-debug-non-zts-20060613/mongo.so'
もし一致しない場合は、php.ini の extension_dir を変更するか、あるいは mongo.so を移動させます。$ php -i | grep extension_dir extension_dir => /usr/lib/php/extensions/no-debug-non-zts-20060613 => /usr/lib/php/extensions/no-debug-non-zts-20060613 -
PHP の起動時に拡張モジュールを読み込むために、次の行を追加します。
extension=mongo.so
*NIX へのインストール
$ sudo pecl install mongo
CentOS あるいは Redhat を使っている場合は、 » RPM からインストールできます。
php.ini ファイルに次の行を追加します。
extension=mongo.so
インストール中に pecl が out of memory となる場合は、php.ini の memory_limit が 128M 以上あるかどうかを確認しましょう。
Windows へのインストール
リリースごとのコンパイル済みバイナリが » S3 にあります。 バージョン、スレッドセーフ/非スレッドセーフ、VCのライブラリのさまざまな組み合わせに対応しています。 アーカイブを Unzip して、php_mongo.dll を PHP 拡張モジュールのディレクトリ (デフォルトは "ext") に置きましょう。
php.ini に次の行を追加します。
extension=php_mongo.dll
OS X
autoconf が見つからない場合は、Xcode をインストールしなければなりません (これは、OS X のインストール DVD の中にあります。あるいは Apple のウェブサイトから無料でダウンロードすることもできます)。
たいていの場合は、pecl でインストールするのがいちばん簡単です。
$ sudo pecl install mongo
XAMPP を使っている場合は、次のコマンドでドライバをコンパイルすることができます。
sudo /Applications/XAMPP/xamppfiles/bin/pecl install mongo
Gentoo
Gentoo には PHP ドライバのパッケージ dev-php5/mongo があり、 次のようにすればインストールできます。
$ sudo emerge -va dev-php5/mongo
PECL を使う場合は、libtool のバージョンが違うというエラーが出るかもしれません。 ソースからコンパイルするには、aclocal と autoconf を実行しなければなりません。
$ phpize $ aclocal $ autoconf $ ./configure $ make $ sudo make install
Red Hat
Fedora や CentOS も含みます。
これらのシステム上の Apache のデフォルト設定では リクエストがネットワーク接続できないようにしており、 データベースに接続しようとすると "Permission denied" というエラーが発生します。もしこの現象に遭遇したら、次のコマンドを実行しましょう。
$ /usr/sbin/setsebool -P httpd_can_network_connect 1
その他のインストール説明
PHP 用ドライバのインストールに関するすばらしいチュートリアルが、 多くのかたによって公開されています。
-
» PHP 5.3.1 with Xdebug, MongoDB and Lithium on Ubuntu 9.10 / Apache 2.2
Jon Adams によるすばらしい動画です。 Apache, PHP, Xdebug, MongoDB, そして Lithium のインストール手順をひとつひとつ説明しています。
-
» Installing MongoDB and the PHP driver on Ubuntu 9.04
Javier Aranda によるスペイン語の記事です (» 英語訳)。
-
» OS X: Installing MongoDB and the PHP Mongo Driver
Matt Butcher によるものです。
In Windows running IIS the directory to instal is "C:\Program Files\PHP\ext". Than you have to install the apropriate MongoDriver version (in my case was mongo-1.1.4-php5.3vc9) and than Restart IIS.
The MongoDB Driver will be available.
If you're running IIS under Windows 7 and have PHP manager installed you'll also need to manually enable the extension. Start IIS Manager, select PHP Manager, under the section labeled PHP Extensions click on Enable or disable an extension, then enable the php_mongo.dll extension, and restart IIS.
To install the Mongo driver on Windows 7 x64 with EasyPHP, you have to use the x86 driver (instead of x64) and non nts :
php_mongo-1.3.2RC1-5.4-vc9.dll actually
I am using XAMPP 1.7.4 (32 bit) on Windows 7. Though it was mentioned that Apache uses a non-threadsafe version of DLL, when used, it was giving me the below error:
PHP Warning: PHP Startup: Unable to load dynamic library
Warning: PHP Startup: Unable to load dynamic library 'D:\xampp\php\ext\php_mongo.dll' - The specified module could not be found.
I had to use the thread-safe version (mongo-1.1.4.zip\mongo-1.1.4-php5.3vc6ts\php_mongo.dll) to get it working.
On windows installation check for VC compilator version inside phpinfo(), if you install incorrect one it wouldn't work.
I tried to run on Apache2 with VC6, and always get folowing error:
Fatal error: Class 'Mongo' not found
Until I look into phpinfo and found MSVC9, after that
I install VC9 dll files and it solve the problem.
Instructions for Manually Installing MongoDB for PHP for use with "XAMPP for Linux":
There were two gotchas that I ran into. "XAMPP for Linux" needs 32 bit libraries, and the php API version must match the php API version of "XAMPP for Linux".
Hopefully this will save someone else time figuring this all out!
1) Install "XAMPP for Linux" AND the "XAMPP for Linux Development Files".
2) Grab the source code from github (in the manual instructions above)
$ tar zxvf mongodb-mongodb-php-driver-<commit_id>.tar.gz
$ cd mongodb-mongodb-php-driver-<commit_id>
There are now some smalls deviation from the manual instructions...
3) PHPize
$ sudo /opt/lampp/bin/phpize
4) Configure
$ ./configure
5) Make changes to the Makefile (XAMPP requires a 32-bit compilation)
- Choose your favorite text editor and open "Makefile"
- Make the following changes:
Line 20: prefix = /opt/lampp
Line 23: prefix = /opt/lampp
Line 25: phpincludedir = /opt/lampp/include/php
Line 27: CFLAGS = -g -O2 -m32
Line 34: EXTENSION_DIR = /opt/lampp/lib/php/extensions/no-debug-non-zts-20100525/
Line 35: PHP_EXECUTABLE = /opt/lampp/bin/php
Make sure you replace </path/to/mongo-php-driver-master>
Line 38: INCLUDES = -I/opt/lampp/include/php -I/opt/lampp/include/php/main -I/opt/lampp/include/php/TSRM -I/opt/lampp/include/php/Zend -I/opt/lampp/include/php/ext -I/opt/lampp/include/php/ext/date/lib -I</path/to/mongo-php-driver-master>/util -I</path/to/mongo-php-driver-master>/exceptions -I</path/to/mongo-php-driver-master>/gridfs -I</path/to/mongo-php-driver-master>/types -I</path/to/mongo-php-driver-master>/mcon
6) Compile
$ sudo make all
7) Copy the static object into the extension directory
$ sudo cp modules/mongo.so /opt/lampp/lib/php/extensions/no-debug-non-zts-20100525/
9) Update your php.ini file
- Grab you favorite text editor and open /opt/lampp/etc/php.ini (you'll probably need to use sudo).
- Add the line: extension=mongo.so
10) Restart "XAMPP for Linux". You should now be able to see Mongo listed in your phpinfo() page! Installation Complete!!!
Good Luck!
