Install mongodb on mac os 10.15 for php7 - mongodb

I have installed mongodb on my mac Catalina 10.15. I have php7.3 version installed as well. Now, I want to use the mongoClient() class with PHP. I tried composer require mongodb/mongodb but it says that the mongodb extension is missing :
Using version ^1.5 for mongodb/mongodb
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- mongodb/mongodb 1.5.1 requires ext-mongodb ^1.6 -> the requested PHP extension mongodb is missing from your system.
- mongodb/mongodb 1.5.0 requires ext-mongodb ^1.6 -> the requested PHP extension mongodb is missing from your system.
- Installation request for mongodb/mongodb ^1.5 -> satisfiable by mongodb/mongodb[1.5.0, 1.5.1].
To enable extensions, verify that they are enabled in your .ini files:
- /etc/php.ini
You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.
Installation failed, reverting ./composer.json to its original content.
So I tried to install the extension for php using the php doc and I get this error :
pear/install/mongodb/php_phongo.c -fno-common -DPIC -o .libs/php_phongo.o
/private/tmp/pear/install/mongodb/php_phongo.c:22:10: fatal error: 'php.h' file not found
#include <php.h>
^~~~~~~
1 error generated.
make: *** [php_phongo.lo] Error 1
ERROR: `make' failed
Any help ?

I also had the same issue after upgrading to MacOS Catalina
Run these two commands;
brew doctor
brew link --overwrite php

I fixed that by installing PHP7.3 using homebrew
here is a post that helped Install PHP 7.3 + xdebug on MacOS Catalina (with homebrew)

I also updated the macos to 10.15 catalina and started the setup. As same as error came during installing the mongodb driver
After Resolving my issue I updated the answer by given below steps:
Step 1:
Run the command: brew install php71
Step 2:
Edit httpd.conf under directory of /etc/apache2/httpd.conf
Add below line
LoadModule php7_module /usr/local/opt/php#7.1/lib/httpd/modules/libphp7.so
then check there should be no other php7_module enabled.
Also add these lines
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
Step 3: Restart apache: sudo apachectl restart
Step 4:
If you need to have php#7.1 first in your PATH run:
echo 'export PATH="/usr/local/opt/php#7.1/bin:$PATH"' >> ~/.bash_profile
echo 'export PATH="/usr/local/opt/php#7.1/sbin:$PATH"' >> ~/.bash_profile
For compilers to find php#7.1 you may need to set:
export LDFLAGS="-L/usr/local/opt/php#7.1/lib"
export CPPFLAGS="-I/usr/local/opt/php#7.1/include"
Step 5:
To have launched start php#7.1 now and restart at login:
brew services start php#7.1
Step 6:
Open new terminal & check php version & it should be 7.1
Step 7:
Then run the command: sudo pecl install MongoDB
& it will install php mongodb driver successfully without any error.
Make sure all step should be followed!!
I did these steps to resolve my MongoDB driver issue for laravel project which not found.

Related

How to enable Xdebug on local Macbook?

Need Xdebug extension enabled in my local development environment.
PHP Version: PHP 8.0.10 (CLI)
OS: Mac ( Chip Apple M1 )
Let me summarize the steps that worked for me always.
Reconfirm x-debug installation on the local work desk or enabled in php.ini by running the following command:
➜ ~ PHP -v
Run the below command to install x-debug:
On Apple M1 hardware, you might instead need to use:
➜ ~ arch -arm64 sudo pecl install xdebug
If you have different architecture, below might be suitable.
➜ ~ arch -x86_64 sudo pecl install xdebug
Note: I had installed PHP using Homebrew before like :
➜ ~ brew install php
Now, with above #2, X-debug should be installed and enabled in php.ini.
You might get something similar as below:
Build process completed successfully
Installing '/opt/homebrew/Cellar/php/8.0.10/pecl/20200930/xdebug.so'
install ok: channel://pecl.php.net/xdebug-3.0.4
Extension xdebug enabled in php.ini
Tips:
Usecase 1: Xdebug installed but not enabled in php.ini.
Steps:>
(a) Read the PHP ini file loaded, active with below.
➜ ~ PHP --ini
(b) Use vi editor and add the following line to php.ini: zend_extension="xdebug.so"
( Note: You may also provide the path instead of just xdebug.so. For example, my local machine path is something like this:- /opt/homebrew/Cellar/php/8.0.10/pecl/20200930/xdebug.so
(c) Save and exit editor and try php -v again to confirm x-debug enabled.
Usecase 2: You had run pecl command with the wrong architecture mentioned.
(a) Uninstall x-Debug with below command:
➜ ~ sudo pecl uninstall xdebug
(b) Re-run install command as shared in Step 2 above with caution using correct architecture.

The MongoDB PECL extension has not been installed or enabled [duplicate]

I am using Ubuntu 12.04 LTS and installed pecl in /opt/lampp/bin/ .
When installing second time its throwing error -
Command run previously -
pecl install mongo
pecl/mongo is already installed and is the same as the released
version 1.5.1 install failed
Now when I am Checking by -
echo extension_loaded("mongo") ? "loaded\n" : "not loaded\n";
It is showing not Loaded.
However I updated the php.ini with extension=mongo.so and restarted the server, but its not working.
Let me now what I am doing wrong.
EDIT
I re instantiated the command and following is the outcome -
Build process completed successfully
Installing '/opt/lampp/lib/php/extensions/no-debug-non-zts-20100525/mongo.so'
install ok: channel://pecl.php.net/mongo-1.5.1
configuration option "php_ini" is not set to php.ini location
You should add "extension=mongo.so" to php.ini
Finally with the help of Neil Lunn I made it the right way.
I added the full path and added the code at the very last line of my php.ini
extension="/opt/lampp/lib/php/extensions/no-debug-non-zts-20100525/mongo.so"
I got the solution for xampp in ubntu linux.
If this command not work for you pecl install mongo
you should type below command
sudo /opt/lampp/bin/pecl install mongo

Xdebug bad Zend API Version Number

I am having trouble upgrading xdebug for MAMP. I was running version 2.2.0 and there was a known issue that I ran into: PhpStorm and Xdebug not breaking in Symfony2 Controller
I tried to upgrade to version 2.2.3 by following the instructions from http://xdebug.org/wizard.php
After downloading and extracting the xdebug tar I ran /Applications/MAMP/bin/php/php5.4.4/bin/phpize
Here is the output:
Configuring for:
PHP Api Version: 20100412
Zend Module Api No: 20100525
Zend Extension Api No: 220100525
I then copied the modules/xdebug.so file into the mamp php5.4.4 extensions dir: `/Applications/MAMP/bin/php/php5.4.4/lib/php/extensions/no-debug-non-zts-20100525/xdebug.
If I run /Applications/MAMP/bin/php/php5.4.4/bin/php -v I get the following:
Xdebug requires Zend Engine API version 220090626.
The Zend Engine API version 220100525 which is installed, is newer.
Contact Derick Rethans at http://xdebug.org/docs/faq#api for a later version of Xdebug.
PHP 5.4.4 (cli) (built: Jul 4 2012 17:28:56)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies
I have restarted MAMP and Apache and tried loading a page with phpinfo() and I do not see Xdebug listed. If I moved the old xdebug.so file back in place the error is removed and phpinfo() show xdebug as enabled
I managed to solve this issue by running
/Applications/MAMP/bin/php/php5.4.4/bin/pecl install xdebug At first I was seeing issues with the Zend API number using pecl. I followed this post: pecl installs for previous php version and set the following:
sudo /Applications/MAMP/bin/php/php5.4.4/bin/pear config-set php_ini /Applications/MAMP/bin/php/php5.4.4/conf/php.ini
sudo /Applications/MAMP/bin/php/php5.4.4/bin/pecl config-set bin_dir /Applications/MAMP/bin/php/php5.4.4/bin/
Not sure if these configs had something to do with it failing before
I have a MAMP server set up on a Mac Pro, I could not get xDebug to work. This was in my logs:
PHP Warning: PHP Startup: xdebug: Unable to initialize module
Module compiled with module API=20160303
PHP compiled with module API=20170718
These options need to match
in Unknown on line 0
This can be fixed by installing the latest xDebug.so. My problem with doing so was that is was writing to the wrong xDebug.so,not the MAMP server:
Build process completed successfully
Installing '/usr/lib/php/extensions/no-debug-non-zts-20160303/xdebug.so'
ERROR: failed to write /usr/lib/php/extensions/no-debug-non-zts-20160303/xdebug.so (copy(/usr/lib/php/extensions/no-debug-non-zts-20160303/xdebug.so): failed to open stream: Operation not permitted)
The second line of #Shawn's answer was the solution:
sudo /Applications/MAMP/bin/php/php7.2.7/bin/pecl config-set bin_dir /Applications/MAMP/bin/php/php7.2.7/bin/
I was then able to build the latest xDebug.so to the right directory using pecl install xdebug.

imagick and mongo on OSX lion with brew

I am trying to install imagick and mongo on osx lion. Note that my php installation is done via homebrew. I have installed the packages correctly and it should work but php returns the following
Warning: PHP Startup: imagick: Unable to initialize module
Module compiled with module API=20090626
PHP compiled with module API=20100525
These options need to match
in Unknown on line 0
PHP Warning: PHP Startup: mongo: Unable to initialize module
Module compiled with module API=20090626
PHP compiled with module API=20100525
These options need to match
in Unknown on line 0
Any clues on how to fix that?
The PHP errors indicate that you've compiled extensions for a different API version (20090626 API is PHP 5.3) from the server you are trying to use the extensions with (20100525 API is PHP 5.4).
I suspect that you have installed PHP 5.4 via homebrew, but managed to pick up the OS X default headers (PHP 5.3) when compiling the extensions. You need to either recompile your extensions with PHP 5.4, or downgrade your web server to PHP 5.3.
You can check the version of PHP headers in your path using php-config:
php-config --version
And the version of PHP and extension API with:
php -i | egrep "PHP (Extension|Version)"
Possible fixes:
Include /usr/local/bin in your path first so the homebrew PHP versions are found in preference to the system default:
export PATH=/usr/local/bin:$PATH
Install PHP 5.3 via Homebrew:
brew uninstall php54
brew install php53
For reference, I'd like to add that
when brew installs php it sets the additional ini files read folder to
/usr/local/etc/php/5.4/php5/conf.d
whilst it actually is
/usr/local/etc/php/5.4/conf.d
you can easily fix that by symlinking
cd /usr/local/etc/php/5.4/
mkdir php5
cd php5
ln -s ../conf.d .

MongoDB Install Error

Just setup a fresh server at MediaTemple (dedicated virtual / CentOS Linux) and installed the developer tools, but Mongo won't install, any ideas?
Also, it's trying to DL version 1.2.10 I assume I can run pecl upgrade mongo once it is installed to go to 2.0.6 right?
Here's my output:
[root ~]# pecl install mongo
downloading mongo-1.2.10.tgz ...
Starting to download mongo-1.2.10.tgz (86,463 bytes)
.....................done: 86,463 bytes
36 source files, building
running: phpize
Configuring for:
PHP Api Version: 20041225
Zend Module Api No: 20060613
Zend Extension Api No: 220060519
building in /var/tmp/pear-build-root/mongo-1.2.10
running: /root/tmp/pear/cache/mongo-1.2.10/configure
checking for egrep... grep -E
checking for a sed that does not truncate output... //bin/sed
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... configure: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.
See `config.log' for more details.
ERROR: `/root/tmp/pear/cache/mongo-1.2.10/configure' failed
You're not installing mongodb with pecl, here you're installing the PHP driver for mongodb.
To install mongodb on CentOS, please follow these instructions here. These instructions show you how to add the 10gen repo, which will then enable you (using yum) to install the latest production-ready mongodb release (2.0.6).
I realise that it's not Ubuntu but egarding your issue with installing the PHP driver, does it make any difference if you run
sudo pecl install mongo
There's some information here on installing the mongo php driver, just replace the 'apt-get' elements with 'yum' as the same libraries, dependencies apply afaik.
Here's a tutorial on using the mongo php driver.