arthankamal
arthankamal

Reputation: 6413

Apache running MongoDB and PHP

I'm using XAMPP in my Mac OSX. I've installed mongodb and copied the .so file into xampp plugins folder. My phpinfo() of the page shows that MongoDB section which is installed.

After i start Apache of XAMPP server, when i code

m = new MongoClient();
$db = $m->mydatabase;
$collection = $db->myCollection;

Its saying some Fatal Error.

If i run mongod command in Terminal window, its working. Then what is the use of installing mongodb in XAMPP server. My Questions are

  1. Why its working like that..?
  2. Is there any way to start mongod when we start Apache server.

Upvotes: 0

Views: 1402

Answers (1)

Sammaye
Sammaye

Reputation: 43884

Why its working like that..?

Installing the PHP driver and the MongoDB server are two completely different things.

This is very basic driver stuff; you require a library or communication layer that can route your PHP programming to the MongoDB server (basically).

Is there any way to start mongod when we start Apache server.

You could make an sh script that looks like:

/etc/init.d/xammp_service_dunno_what_it_is_called start
/etc/init.d/mongodb start

Then you could just attach to the startup, or even better you can just attach both services (XAMPP and MongoDB) to the startup of your computer.

However, as far as I know, there is no way to create a sort of trigger mechanism that will load up MongoDB when the OS detects that you have started running Apache.

Upvotes: 2

Related Questions