how to use MongoDB in laravel4? - php

I have successfully installed Mongodb on my win 7 system. I also installed php extension for MongoDB on my Wamp server and it works perfectly; yet I wish to know how I can use MongoDB in my laravel4 projects. I will like to use mongovel package but when I run 'composer update' there is always an error: php extension not found in your system. Also I installed jessengers package but got an error: MongoClient not available. Please I need help on how to get out of this. Thanks

You need to make sure that the extension is also available on the command line. In many cases there is a different php.ini for CLI. You can find this out by running:
php --ri mongo
if that does not provide any sort of output about version and settings, you don't have it installed properly.
Then you can use php --ini to find out where your INI files are - the ones that are used for running PHP on the command line

Related

Unable to install phalcon 2.x on VPS from 1and1 hosting

I ran into a troublesome issue.
I'm using 1 and 1 virtual private server redhat linux. The server's default PHP version is PHP 5.3.
I do have installed PHP 5.5 on the server. I switch to PHP 5.5 using alias php='path to php'.
I run command php -v to see if the version has changed, indeed it has - the PHP version is now 5.5.
However I am still unable to install phalcon, when I run the command ./install -i I get this error message:
Php 5.3 is not supported.
Any ideas how to resolve this problem?
Alias will not work in your case because it changes php path only for your terminal, not globally.
I'm not a redhat user so can't give you exact steps but a kinda dirty solution is to find your php binary (on debian is in /usr/bin/, /bin/ or /usr/local/bin), rename it to for example php5.3 and in this place make a symbolic link to new php.
Remember that your php webserver (apache, nginx or whatever you use) should also have an updated php! What is more, to compile phalcon you'll need also an updated phpize and other dependencies. I'm not a linux expert so cannot tell you exactly which parts of php5-dev did changed between PHP 5.3 and 5.5 and which did not.
Alternatively you can just clone from github and install an old phalcon 2.x which is also great. The new 3.0 doesn't have that much breaking features. It's killing feature is PHP7 which it seems that you're not going to use. Phalcon 2.x requires PHP5.4+
I belive there are better ways how a php update should be performed but I don't know them.

MongoDb Extension for Yii 2 throwing error of extension not installed

I'm trying to install Yii2 mongo extension, I have already installed the mongo php driver and it showing in phpinfo. Please refer the screenshot for error. I have tried with both mongo and mongodb drivers, none are working.
I have tried the composer command
composer require "mongodb/mongodb=^1.0.0
from
http://us1.php.net/manual/en/mongodb.tutorial.library.php
its still the same output.
Check if there is a second php.ini for CLI version - probably mongodb is not added there (or just commented out). php --ini in console should help you find it. Fix configuration, restart apache and it should be fine.
Mongo driver is deprecated, in place of that mongodb drivers are added for newer version of PHP. Try installing Mongodb driver.
Steps for installation
http://php.net/manual/en/set.mongodb.php
Try with Xamp, I had issue with wamp and mongodb in windows.
refer this link for procedure.

How do I solve this PHP-PEAR error / install PEAR on Fedora?

I'm trying to save an old, failing web-server setup consisting of Fedora, PHP, PEAR, and Oracle.
With some difficulty (I'm very new to all four), I've been able to set up something similar on a newer system. I used Fedora 19, PHP 5.5.4 (with Apache 2.4.6), and Oracle 11g.
That just leaves PEAR.
Now, from what I understand, PEAR is some PHP code, like a library, which PHP Web Applications can use to save time from having to code them again - database connection, for example.
But I don't know what to do with it, or even how to get it. Copy paste from my old system? Download using the CLI using yum? Are there packages I need to be aware of, or is it just a one download-one install thing?
For instance, a basic PHP webpage with the following code:
<?php
phpinfo();
?>
works fine on the new server setup, so I'm assured that everything else is working. But when I try to load the PHP files from the other server, it returns an Internal Server Error. I checked the error_log files under /etc/httpd/logs, and most of the errors appear as below:
PHP Fatal error: require_once(): Failed opening required 'MDB2.php' (include_path='.:/usr/share/pear:/usr/share/php') in /var/www/html/hrweb/includes/functions.php on line 4
EDIT:
According to the PEAR Website, PEAR is included upon the installation of PHP, though not all modules / packages are there. Typing in the command pear in the CLI does confirm it is installed, though it does not help the issue.
I got the MDB2 package via pear install MDB2, though apparently, MDB2_Driver_oci8 is required. Whenever I try to download that, I get the following:
"MDB2_Driver_oci8" version "1.4.1" does not have REST XML available
In addition to this, I also tried to download OLE, which gets me the following:
No releases available for package "pear.php.net/OLE"
This was also previously the error of trying to download MDB2_Driver_oci8.
Thanks.
You have to install the (surprise!) MDB2 package to get MDB2.php:
$ pear install mdb2
and the adapter of your choice:
$ pear install mdb2_driver_mysql-beta
Then make sure the PEAR php directory is in your include path - see the PEAR manual.
"MDB2_Driver_oci8" version "1.4.1" does not have REST XML available
try to install the beta version:
$ pear install mdb2_driver_oci8-beta
No releases available for package "pear.php.net/OLE"
You're trying to install the stable version, but OLE does not have any stable version (yet): http://pear.php.net/package/OLE/download
Append either -alpha or -beta after OLE:
$ pear install OLE-beta

CentOS - Mongo class not found in PHP

I need the MongoDB PHP driver on my CentOS 5.4 machine. My PHP version is 5.1.6. I downloaded the RPM and installed it. That created several files in /usr/bin directory. I copied
/usr/bin/mongo
to
/usr/lib/php/modules
which was what extension_dir showed on doing phpinfo();.
I also added
extension=mongo.so
in /etc/php.ini.
However on executing my PHP script, i still get
Mongo class not found.
What's going wrong here ?
Also, my phpinfo() shows PHP version 5.1.6 whereas running PHP from command line shows 5.3.3. Could anything be wrong with that ?
Thanks in advance.
You're saying your webserver and command line PHP report different versions. These are going to be installed in different locations, and their extensions are API incompatible with each other.
When you installed the php_mongo extension, it may have used the command line php to determine the directory to install the extension to.
Make sure you have the correct php_mongo for the php version of your webserver, and it is in the correct extensions directory. (get the directory from the php.ini returned by phpinfo())
I hope you realise PHP 5.1 is also many years out of date. Unless you have a specific reason to use a version that old, you should also look at upgrading to a more recent version.
Edit:
Just read your comment "I must also mention that /usr/bin/mongo is a binary executable file but its not having a .so extension. Im copying it as is to /usr/lib/php/modules"
No no no! :)
This is the mongo command line client. This is not the PHP extension!
You can run a find /* -name "mongo.so" to see where the installer put the file, this will probably also give you an indication of which version of PHP it was installed for.
It looks as though you are confusing the RPM-packages for the MongoDB server with the requirements to install the MongoDB PHP driver. The PHP driver provides access to the server from your PHP applications, and does not install any command line tools.
restart httpd !
yum service httpd restart

Mongo PHP Driver 1.2.10 with MAMP

I'm trying to get the latest Mongo Driver to work with MAMP 1.9.6 on OS X 10.5.8.
I built it successfully from source since it seems that there are no pre-compiled releases, included it into the right directory and restarted the apache.
But PHP doesn't recognize the extension. I used the 1.0.11 driver previously which worked fine, but I need the new version, because Doctrines ODM requires it.
When I replace the 1.2.10 mongo.so with the 1.0.11 and restart apache mongo is available. I don't get what could be wrong.
Anyone had this behaviour or any guesses to get this to work?
Update: The PHP error log shows the following:
[01-Jun-2012 22:02:37] PHP Warning: PHP Startup: mongo: Unable to initialize module
Module compiled with module API=20060613
PHP compiled with module API=20090626
These options need to match
in Unknown on line 0
I'm not quite sure what it means?
2. Update:
I was finally able to sync the API version of phpize.
But now I'm not able to build the driver anymore.
I do the following:
phpize
./configure
make
sudo make install
But at the make command I'm getting tons of syntax errors. Seems that it can't find several header files.
The very first one is the zend_config.h and really I just have those other two files:
zend_config.nw.h
zend_config.w32.h
I downloaded the MAMP components to get this files. Why am I missing this one? And there are a lot of others.
I'm using PHP 5.3.5 Is there a way to get those header files from a different source?
I followed the instructions at Develop MongoDB web apps with MAMP under Mac OS X to successfully build mongo.so for MAMP with php 5.3 on OS X 10.7.3.
I'm adding this for historical purposes -- I guarantee that if you're having the same set of problems, you'll want to do this.
Personally, I had a really difficult time getting MAMP's php version to play nicely with the extension builds that I was trying to make.
I discovered that the problem was that MAMP really hadn't been set up to add extensions in general, and during the compilation of the mongo php drivers, it wasn't installing it in the right place -- so I followed the following tutorial on preparing MAMP for additional pecl and pear extensions.
After following those steps to prepare MAMP for adding extensions, you can easily install any extension.
At the part where it starts talking about adding an extension, use sudo pecl install mongo and restart apache from your MAMP interface.
I ran into the same problem when upgrading from PHP 5.3 to 5.4 and was able to solve it by following these steps:
Make sure to upgrade php5-cli as well as just php5 and php5-common
Uninstall the mongo drive
sudo pecl uninstall mongo
Re-install the mongo driver
sudo pecl install mongo

Categories