unable to load mongo extension for php - php

After trying for two days to get this to run;
sudo pecl install mongo
I finally got it done and added the extension to php.ini only to find out that it will not work for me.
This is what the install output was at the end;
Libraries have been installed in:
/tmp/pear/temp/pear-build-rootVYRzXc/mongo-1.5.8/modules
running: make INSTALL_ROOT="/tmp/pear/temp/pear-build-rootVYRzXc/install-mongo-1.5.8" install
Installing shared extensions: /tmp/pear/temp/pear-build-rootVYRzXc/install-mongo-1.5.8/usr/lib/php5/20090626/
Installing '/usr/lib/php5/20090626/mongo.so'
install ok: channel://pecl.php.net/mongo-1.5.8
# I edited etc/php54/php.ini here
sudo service apache2 restart
php --ri mongo
Extension 'mongo' not present.
But when I did mongo --version I get MongoDB shell version: 1.4.4 which may be from my modulus installation. Could that cause mongo not to load?
When trying;
$mongoConn = new MongoClient("mongodb://<user>:<pass>#proximus.modulusmongo.net:27017");
I get;
Fatal error: Class 'MongoClient' not found

Verify that mongo.so is found on in extension_dir:
php -i | grep extension_dir
Then cd to that folder and check for presence of mongo.so.
If present, make sure you have this in php.ini
extension=mongo.so
If this does not work: In certain virtual systems, such as those based on Docker, you may need to install your extension as the user associated with the "domain" or instance. A global (root user) installation may not work.

Related

Install phpredis MAC OSX

Can anyone help me install php-redis in MAC OSX .
brew install php-redis
not working.
pecl install php-redis
also not working getting -
invalid package name/package file "php-redis".
Homebrew Error:
homebrew_error
git clone https://www.github.com/phpredis/phpredis.git
cd phpredis
phpize && ./configure && make && sudo make install
Add extension=redis.so in your php.ini
brew services restart php#7.2
make test
You can check working or not
php -r "if (new Redis() == true){ echo \"\r\n OK \r\n\"; }"
As of 2019, with homebrew php7.2 and up, pecl is now installed by default alongside the php binaries.
To see this for yourself type which pecl.
Steps to install
Check your version of redis, then find a suitable version of the extension here.
If unfamiliar with pecl, type pecl to see the options.
Issue pecl install redis-5.0.2. (or your version). Enter no to each question asked if you're not sure.
If that succeeds check the new file it created at: /usr/local/lib/php/pecl/20180731/redis.so
The install will have added extension="redis.so" to top of your php ini.
Check that by opening the file /usr/local/etc/php/7.3/php.ini.
(assuming you're on 7.3 there)
brew services restart php.
php -i | grep Redis
Redis Support => enabled
Redis Version => 5.0.2
This is what I just did in September 2019 and it works for me.
If what mwal wrote above doesn't work (please try his/her answer first),
first, try to uninstall first (if you have it but broken):
sudo pecl uninstall redis
and after that run:
sudo pecl install redis
After that, ini the php.ini, use full path for the extension.
Mine was /usr/local/Cellar/php#7.3/7.3.21/pecl/20180731/redis.so (assuming you are using php#7.3)
so at the top of my php.ini file is like this:
extension="/usr/local/Cellar/php#7.3/7.3.21/pecl/20180731/redis.so"
Here are steps to use pickle, for PHP >= 7.3 (tested with 8.1):
brew install pickle
pickle install redis
Find your php.ini location via php -i|grep php.ini
Edit the php.ini, insert extension=redis. Preferable at Dynamic Extensions section.
No restart of Apache httpd service is required. You may test your PHP code with Redis
Bonus
If you use VS Code, to enable intellisense / auto complete, at Preference -> paste intelephense.stubs at Search setting box -> Add Item -> select redis.
If you got the following error,
Please make sure the PHP Redis extension is installed and enabled
despite doing everything in the verified answer above, try valet restart . It worked for me
I have tried all these solutions but didn't work for me for a while so I tried this link https://developer.redis.com/develop/php/ from the original docs and it works as charm
If someone gets an error during sudo pecl install redis
Warning: mkdir(): File exists in System.php on line 294
PHP Warning: mkdir(): File exists in /opt/homebrew/Cellar/-----/pear/System.php on line 294
that means you need to create the broken directory manually.
Try to create the directory...
pecl config-get ext_dir | pbcopy
mkdir -p {paste clipboard value}
# in my case, it was
mkdir -p /opt/homebrew/lib/php/pecl/20200930
Now try to install any pecl extensions.
sudo pecl install redis
After installing any extension, restart php
brew services restart php
Happy coding :)

MongoClient Not found connection php mongolab

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.

PHP redis error

I installed the php redis extension. But when I run the test code, I got the following error:
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20090626+lfs/redio.so' - /usr/lib/php5/20090626+lfs/redio.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Fatal error: Class 'Redis' not found in /var/www/test/redisTest.php on line 2
My php version is 5.3.10, I installed the new version of phpredis.
May I get your help?
THANKS!
The install steps are:
git clone https://github.com/nicolasff/phpredis.git
cd phpredis
phpize
make
make install
Then add a config file in /etc/php5/fpm/confi.d to load redis.so
I use PHP 5.3 and installing PHP-Redis using below steps worked just fine for me:
Install pecl extensionsudo pecl install redis
In php.ini, you may need set extension_dir to correct value. (can be usr/lib64/php/modules as above command placed the redis.so in this directory). In my case, I didn't set this.
Add below line to php.ini:extension=redis.so
Restart Apache/PHP-FPM
To verify if you have got redis installed you can do this
php -m | grep redis
Create a file PHP with echo phpinfo(); in it and see if the module is showing up. If you do not see the module then it is not being loaded correctly.
In the PHP5.3 and Amazon Linux AMI (Same as Centos OS 5)
install libs
yum install php-pear php-devel make gcc wget
install redis
cd /opt/
mkdir /opt/redis
wget https://redis.googlecode.com/files/redis-2.6.14.tar.gz "or last version"
tar -zxvf redis-2.6.14.tar.gz
cd redis-2.6.14
make
make install
install php-redis by pecl
pecl install redis
configuration option "php_ini" is not set to php.ini location
You should add "extension=redis.so" to php.ini
reload the web service httpd
service httpd reload
verify that the extension has been installed
php -m
[PHP Modules]
bz2
...
**redis**
...
[Zend Modules]
Download the proper library file according to your server environment( ex. x86). also, check for your PHP is thread-safe or not and download the Redis library accordingly. then place the library file inside the extension folder. you need to mention the library inside your php.ini as given below.
extension=redis.dll
then restart the server once, and check it's working properly or not.
if you have command line PHP, you can check it in the command line PHP as,
php r("print_r(get_loaded_extensions());")

Can't get mongo.so extension to load after updating PHP to 5.3

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

Fatal error: Class 'XSLTProcessor' not found

I'm using XAMPP Server 1.7.7
While opening the php file, i receive the error
Fatal error: Class 'XSLTProcessor' not found
Install the XSL extension to get that class. This might be as easy as uncommenting (remove the starting ';') on the line that reads extension=php_xsl.dll in php.ini on Windows, or apt-get install php5-xsl on most Linux-based systems. For custom builds of PHP, use configure option --with-xsl (requires package libxslt1-dev).
Its necessary install the XLS extension.
My solution by my context.
I'm using one docker container contain ubuntu base and using php-fpm (ie if you simply already use linux ubuntu in the same).
The steps to install this extension in my context were:
First search xsl extension on linux repository
sudo apt-cache search xsl
I ended up finding the php5-xsl, so it was only install
sudo apt-get install php5-xsl
that the installation process the setup configuration is already added, if does not happen, just make yourself
sudo vim /etc/php5/mods-available/xsl.ini
insert this content:
extension=xsl.so
(obviously the paths are according to your php configuration settings, but my example is the default configuration)
Restart you php fpm and done (sudo service php5-fpm restart)!

Categories