The php manpage sais, you have to install sqlite via PECL, so I tried the latest version:
cd /tmp/
wget https://pecl.php.net/get/SQLite-1.0.3.tgz
tar xvzf SQLite-1.0.3.tgz
cd SQLite-1.0.3/
phpize
But I cannot install php_sqlite on Ubuntu 15.10 like this. I get an error at make :
/tmp/SQLite-1.0.3/sqlite.c: In function 'zif_sqlite_open':
/usr/include/php5/main/php_globals.h:32:29: error: 'struct _php_core_globals' has no member named 'safe_mode'
And many more, so is there an actual version working on PHP 5.6?
I want to run an old program that uses the function sqlite_open
And installing the package didn't make it work:
apt-get install php5-sqlite
So maybe there's a good wrapper library around that uses SQLite3::open to simulate the old functions?
I've been wracking my brain for a couple of days on this, but this finally worked for me:
sudo apt-get install php5.6-sqlite3
I have php5.6 as an executable so I then confirmed that php5.6 -m showed sqlite3 to be loaded and it was.
After that, I was able to execute the following simple script. Previously it was telling me that the class SQLite3 was not found.
<?php
class MyDB extends SQLite3
{
function __construct()
{
$this->open('test.db');
}
}
$db = new MyDB();
if(!$db){
echo $db->lastErrorMsg();
} else {
echo "Opened database successfully\n";
}
As far as I can see the pecl page shows that package was last updated in 2004. The link you linked also states: "(PHP 5 < 5.4.0, PECL sqlite >= 1.0.0)". Simply said It's not for 5.6.
Regardless you should just install the default package instead of using pecl when this is an option. For ubuntu this is php5-sqlite.
The extension you linked is very old. I would recommend taking a look at SQLite3 which should be included by default.
Related
sorry if there is a duplicate question for this but I'm trying to set this up for hours now and it just doesn't work.
I have a Debian 11 server with "KeyHelp" installed on it (little brother of plesk). It comes with PHP 7.4 but provides a simple Dashboard where you can install other PHP versions. I installed PHP 8.1 and tried to install the mongodb extension via PECL.
After "pecl install mongodb" I added "extension=mongodb.so" and after that didn't show up the extension on the phpinfo page, I double checked if the extension is really in the extension folder of php, where it was.
Turns out that I installed the extension for PHP 7.4 and not for PHP 8.1. Finally I tried to force PECL to install it for PHP 8.1 but it says "phpize8.1 command not found". I found no way to install phpize8.1, can somebody help me out with that?
Thanks in advance!
I am using Ubuntu 20.04
I have PHP 8.1 version. You have to install modules of PHP
sudo apt install php8.1-mongodb
List the modules
php -m
It's not exactly Debian. I hope it helps you.
If you run command:
sudo apt install php-dev
System will install automatically the correct version of php{x}-dev for your distribution, and all it's dependencies, included PECL.
another way is try to run:
/usr/bin/phpize
If this command works, you need to add phpize to your PATH:
PATH=$PATH\:/usr/bin; export PATH
In this way phpize will work in future.
I have installed mongodb on a new Ubuntu 18.04 server. I can access and work with the database through the command line, but cannot access it via PHP, and was wondering how other people have gotten it to work.
Following a new build of Ubuntu 18.04, and installation of LAMP, I ran:
sudo apt install mongodb-server php-pear php7.2-dev
sudo pecl install mongodb
I then added the mongodb.so extension to the php.ini file, and a phpinfo(); page shows mongodb as installed. So far so good.
If I browse to a test php page ($mongo=new Mongo();), the page fails to load though.
Through web searches, I find the https://github.com/alcaeus/mongo-php-adapter page come up a lot, and I have run the composer installation command there, but to no avail.
Installed versions are: Ubuntu 18.04.2 LTS; mongoDBv3.6.3; php 7.2.17; Apache 2.4.29
I was wondering what steps other people who have gotten PHP to work successfully with Mongodb have followed? I plan to scrap this server and start from a fresh VM install again.
I was able to install php-mongodb after adding the ppa repository ondrej/php:
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt-get install php-mongodb
try:
sudo apt-get install php-mongodb
worked for me
It appears that you're attempting to use the Mongo class from the legacy driver, but you're using the non-legacy driver so that class doesn't exist. Please look at the documentation for the updated version of the driver here. You might also consider using the MongoDB PHP Library to abstract away many of the driver calls.
Please note that there are also compatibility considerations between your versions of the PHP library, MongoDB, and the MongoDB PHP driver. You can find the compatibility information for them here.
Fatal error: Uncaught MongoDB\Driver\Exception\ConnectionException: Server at localhost:27017 reports wire version 0, but this version of libmongoc requires at least 3 (MongoDB 3.0)
I have PHP 7.0.13, MAMP and MongoDB. The MongoDB extension for PHP has been installed.
I have the following:
<?php
ini_set('display_errors', 'On');
require 'vendor/autoload.php';
var_dump(extension_loaded('mongodb'));
echo phpversion('mongodb')."\n";
$m = new MongoDB\Driver\Manager("mongodb://localhost:27017");
// Query Class
$query = new MongoDB\Driver\Query(array('age' => 30));
// Output of the executeQuery will be object of MongoDB\Driver\Cursor class
$cursor = $m->executeQuery('testDb.testColl', $query);
// Convert cursor to Array and print result
print_r($cursor->toArray());
?>
What does 'wire' refer to in this context, and does anyone have a solution for this problem?
I have got the problem on Linux Mint 19 (think that Ubuntu 18+ can have the same problem):
Server at IP:27017 reports wire version 2, but this version of libmongoc requires at least 3 (MongoDB 3.0)
As the message says - server driver version and mine one are different.
This happened because I installed php mongo driver with the command:
sudo apt-get install php7.2-mongodb
The SOLUTION was to completely uninstall php mongo driver:
sudo apt-get remove --auto-remove php-mongodb
and then install php-mongodb from Pecl mongodb php extension:
sudo pecl install mongodb-1.4.4
(If you bump into error pecl: command not found, just install PEAR package in order to use pecl installer. sudo apt-get update && sudo apt-get install php-pear)
After that add the next line to your php.ini file:
extension=mongodb.so
Don't forget to reload the web server:
sudo systemctl reload apache2
That's it. Everything should work!
If anyone searching for solution for Centos 7, here's what you need to do (based on Evgeny Melnikov answer):
yum erase php-pecl-mongodb && pecl uninstall mongodb
pecl install mongodb-1.9.1
Then add extension=mongodb.so to your php.ini file and restart php-fpm.
I have a Raspberry Pi 3B with mongo version. It runs an older version of MongoDB, so I found an equally old version of pymongo and it worked.
mongo --version
MongoDB shell version: 2.4.14
min_wire_version was added sometime after the release of Mongo 2.4.14, so I just installed pymongo drivers that were equally as old.
pip install pymongo==2.4.2 worked for me.
https://pecl.php.net/package-info.php?package=mongodb&version=1.13.0
pecl uninstall mongodb
pecl install mongodb-1.13.0
I'm trying to connect to Mongolab db server, but I get this error:
Fatal error: Class 'MongoClient' not found in /home/viviane/public_html/sk/zizi/head.php on line 33
I suspect it is related to the PHP Mongo Driver, but I don't know how. If I try to connect to a remote mongodb server
$uri = "mongodb://dzyasser:dzyasser#ds049624.mongolab.com:49624/serverdb";
$options = array("connectTimeoutMS" => 30000);
$connection = new MongoClient($uri, $options );
So why am I still getting this error when I'm trying to connect to a remote Mongodb server (Mongolab)?
Its look like you don't have MongoDB PHP extension in your system.
Try to install MongoDB PHP extension in order to solve your problems with the MongoClient class. This is how I setup MongoDB PHP extension in OS X.
Get MongoDB extension from PECL
$ sudo pecl install mongodb
Make a copy of php.ini.default
$ sudo cp /etc/php.ini.default /etc/php.ini
Put this line on php.ini than save
extension=mongodb.so
Check the installation using this command
php --re mongodb
Or create simple php document that contain phpinfo() function
If you get problem with writing the extension, please read this post.
I assume, the Mongo driver is installed and loaded.
If so, since the error message says the MongoClient class cannot be found, it might be caused by a namespace used in your script. If so, try
$connection = new \MongoClient($uri, $options );
Regardless of whether you are connecting locally or remotely, it seems PHP requires the mongo DB service to be running on your server. So install it like so:
a) Install mongodb service
$ sudo apt-get install -y mongodb
b) Add the php drivers if they are missing:
$ sudo apt-get install php5-dev php5-cli php-pear -y
$ sudo pecl install mongo
c) Then open your php.ini file and add to it the extension line "extension=mongo.so":
$ sudo vi /etc/php5/apache2/php.ini
> extension=mongo.so
d) Then restart apache
$ sudo service apache2 restart
Disclaimer: This example was tried on Ubuntu 14.04 LTS with Apache web-service and PHP5 installed. If your installation is different, follow the same approach but issue appropriate commands. If you have no access to SSH or sudoer privileges, contact someone who can help you do this.
I had PHP 5.2 with MongoDB installed on Debian Lenny x64 and everything was fine.
After updating PHP to 5.3 (dotdeb) I can't get MongoDB to work, I always get an error
Fatal error: Class 'Mongo' not found (...)
Everything else works fine, all default modules are working.
My php.ini:
extension_dir = "/usr/lib/php5/20090626"
extension=mongo.so
Mongo.so is in same location as written above.
But when I run php -m in console to check loaded modules, "mongo" isn't listed there.
I can't use dl('mongo.so') to load module at runtime, because this function was deprecated in PHP 5.3.
May be I should recompile mongo somehow, I just don't know how to do that because I'm not very good in *nix commands.
Thanks for your help!
UPDATE
Also may be it's worth saying that before my mongo.so was in /usr/lib/php5/20060613 and I manually copied it to "/usr/lib/php5/20090626" because it seems that after updating my PHP all modules are located there.
The extension module api has changed between php5.2 and php5.3. When php tries to load an extension module both sides have to "present" an api magic key that identifies the api version. If those numbers don't match the module is not loaded/activated.
Try sudo pecl install mongo again to get an extension module that fits your new php version.
Try re installing mongo & restart service
sudo pecl uninstall mongo
sudo pecl install mongo
sudo service apache2 restart
This will install mongo in to newer version
I spent a little time trying to fix this, I am guessing you had a previous mongo install. The way I fixed it was by:
I installed php5-dev:
sudo apt-get install php5-dev
cd /etc/php5/apache2/conf.d/
sudo rm -rf mongo.ini
I then viewed my php.ini and removed extension=mongo.so
Then:
sudo pecl uninstall mongo
sudo pecl install mongo
sudo service apache2 restart