downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

チュートリアル> <マニュアル
[edit] Last updated: Fri, 25 May 2012

view this page in

インストール手順

MongoDB PHP ドライバは、ほぼすべてのシステムで動作します。 Windows、Mac OS X、Unix そして Linux。リトルエンディアンマシンおよびビッグエンディアンマシン。 32 ビットマシンおよび 64 ビットマシン。PHP 5.1、5.2 および 5.3。

この » PECL 拡張 モジュールは PHP にバンドルされていません。 このページでは、さまざまなシステムへのインストールに関するより詳細な情報とトラブルシューティングを扱います。

*NIX へのインストール


$ sudo pecl install mongo

を実行します。

CentOS あるいは Redhat を使っている場合は、Csoke Arpad が作った » RPM を使うことができます。

php.ini ファイルに次の行を追加します。


extension=mongo.so

インストール中に pecl が out of memory となる場合は、php.ini の memory_limit が 32M 以上あるかどうかを確認しましょう。

手動インストール

ドライバの開発者や最新のバグフィックス版に興味のあるかたは、 » Github にある最新のソースコードからドライバをコンパイルすることもできます。 Github に行き、"download" ボタンをクリックしましょう。そして以下のようにします。


$ tar zxvf mongodb-mongodb-php-driver-<commit_id>.tar.gz
$ cd mongodb-mongodb-php-driver-<commit_id>
$ phpize
$ ./configure
$ sudo make install

php.ini を次のように変更します。

  • extension_dir 変数が mongo.so の場所を指すようにします。 ビルド中に、PHP ドライバをどこにインストールするのかがこのように表示されます。

    
          Installing '/usr/lib/php/extensions/no-debug-zts-20060613/mongo.so'
    
    
    この場所が PHP の拡張モジュール用ディレクトリと一致するかどうかは、次のようにして確認します。
    
          $ php -i | grep extension_dir
            extension_dir => /usr/lib/php/extensions/no-debug-zts-20060613 =>
          /usr/lib/php/extensions/no-debug-zts-20060613  
    
    
    もし一致しない場合は、php.ini の extension_dir を変更するか、あるいは mongo.so を移動させます。

  • PHP の起動時に拡張モジュールを読み込むために、次の行を追加します。

    
          extension=mongo.so
    
    

OS X

autoconf が見つからない場合は、Xcode をインストールしなければなりません (これは、OS X のインストール DVD の中にあります。あるいは Apple のウェブサイトから無料でダウンロードすることもできます)。

XAMPP を使っている場合は、次のコマンドでドライバをコンパイルすることができます。


sudo /Applications/XAMPP/xamppfiles/bin/pecl install mongo

MAMP を使っている (あるいは XAMPP を使っているけれども上のコマンドがうまく動かない) 場合は、コンパイル済みのバイナリを » Github から取得します (最新版の "osx" の中から、PHP のバージョンにあわせたものをダウンロードします)。 アーカイブから mongo.so を取り出して MAMP あるいは XAMPP の拡張モジュール用ディレクトリに追加し、 php.ini に


      extension=mongo.so

を追加してからサーバーを再起動します。

Gentoo

Gentoo には PHP ドライバのパッケージ dev-php5/mongo があり、 次のようにすればインストールできます。


$ sudo emerge -va dev-php5/mongo

PECL を使う場合は、libtool のバージョンが違うというエラーが出るかもしれません。 ソースからコンパイルするには、aclocal と autoconf を実行しなければなりません。


$ phpize && aclocal && autoconf && ./configure && make && make install

Red Hat

Fedora や CentOS も含みます。

これらのシステム上の Apache のデフォルト設定では リクエストがネットワーク接続できないようにしており、 データベースに接続しようとすると "Permission denied" というエラーが発生します。もしこの現象に遭遇したら、次のコマンドを実行しましょう。

$ /usr/sbin/setsebool -P httpd_can_network_connect 1 
そして Apache を再起動します (この問題は、SELinux の環境で発生します)。

Windows へのインストール

リリースごとのコンパイル済みバイナリが » Github にあります。 バージョン、スレッドセーフ/非スレッドセーフ、VCのライブラリのさまざまな組み合わせに対応しています。 アーカイブを Unzip して、php_mongo.dll を PHP 拡張モジュールのディレクトリ (デフォルトは "ext") に置きましょう。

最新の (リリース前の) コードをコンパイルした Windows バイナリも、 コミットのたびに作られています。この zip には、php_mongo.dll が入った zip と version.txt が含まれています。version.txt は常に手元に置いてください。 疑問や問題が発生した場合に、それを使えば正確なバージョンを開発者に伝えることができます (バージョン番号は非常に長くて意味がなさそうな数値ですが、 開発者たちにとってはそれが重要な意味を持つのです!)。

最新のバグフィックス版を取得するは、 インストールしている PHP に対応したバイナリをダウンロードします。

そして、php.ini に次の行を追加します。


extension=php_mongo.dll

その他のインストール説明

PHP 用ドライバのインストールに関するすばらしいチュートリアルが、 多くのかたによって公開されています。



チュートリアル> <マニュアル
[edit] Last updated: Fri, 25 May 2012
 
add a note add a note User Contributed Notes インストール手順
soni.harriz 21-Mar-2012 08:17
i found that php.ini file located in /etc/php.ini , when i open the file, it is empty. i have added the "extension=mongo.so" in the file, but still it didn't work. Can you tell me how to resolve it? every answer is fully appreciated. thanks before
enzo at smshome dot net 10-Aug-2011 08:49
There is no php_mongo.dll for x64 PHP. PHP doesn't load pre-compiled version (error: "%1 is not a valid Win32 application")
tiago dot braga at gmail dot com 08-Aug-2011 09:04
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.
rishi at plavaga dot in 27-Jun-2011 01:25
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.
Andrey 01-Jun-2011 04:54
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.
poorpuer at gmail dot com 26-Oct-2010 08:26
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.
Anonymous 12-Mar-2010 10:41
I was only able to solve an xmapp install problem by accessing the cached version of this page - which was at the time hosted at mongo.

in the comments someone said

Setup on XAMPP
Install the Developer package for XAMPP
Make sure the the Apple Developer Tools are installed
!!!Edit your php.ini file with extension=mongo. For some reason, the build did not work until I did that.
if XAMPP install in your Application folder, run sudo /Applications/XAMPP/xamppfiles/bin/pecl install mongo
Restart XAMPP

which worked.

using the github packages it ended up being compiled with different versions of whatever and then threw an error in the log and wasnt included.
cap at unagon dot com 26-Feb-2010 01:52
For Debian users: apt-get install php5-dev will install phpize for you.

 
show source | credits | stats | sitemap | contact | advertising | mirror sites