13

I'm using with latest php version 7.2 on macOS (Mojave / Big Sur / Monterey / Ventura / Sonoma) and receiving error like

 $composer require mongodb/mongodb
Using version ^1.4 for mongodb/mongodb
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)

For more information about question : see the screenshoot

enter image description here

Your requirements could not be resolved to an installable set of packages.

Problem 1 - mongodb/mongodb v1.4.x-dev requires ext-mongodb ^1.5.0 -> the requested PHP extension mongodb is missing from your system. - mongodb/mongodb 1.5.x-dev requires ext-mongodb ^1.6 -> the requested PHP extension mongodb is missing from your system. - mongodb/mongodb 1.4.2 requires ext-mongodb ^1.5.0 -> the requested PHP extension mongodb is missing from your system. - mongodb/mongodb 1.4.1 requires ext-mongodb ^1.5.0 -> the requested PHP extension mongodb is missing from your system. - mongodb/mongodb 1.4.0 requires ext-mongodb ^1.5.0 -> the requested PHP extension mongodb is missing from your system. **- Installation request for mongodb/mongodb ^1.4 -> satisfiable by mongodb/mongodb[1.4.0, 1.4.1, 1.4.2, 1.5.x-dev, v1.4.x-dev].

Installation failed, reverting ./composer.json to its original content.

I have already installed mongoDB extension still receiving problem enter image description here

Not sure what I've missed steps to installation. If anyone can help me with this composer problem, I'd greatly appreciate it. in advance Thanks.

hakre
  • 193,403
  • 52
  • 435
  • 836
Kalpesh Gamit
  • 939
  • 1
  • 11
  • 30

5 Answers5

37

composer require mongodb/mongodb --ignore-platform-reqs

composer require mongodb/mongodb --ignore-platform-reqs
composer require jenssegers/mongodb --ignore-platform-reqs

Using version ^3.4 for jenssegers/mongodb
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 2 installs, 0 updates, 0 removals
  - Installing mongodb/mongodb (1.4.2): Downloading (100%)         
  - Installing jenssegers/mongodb (v3.4.5): Downloading (100%)         
jenssegers/mongodb suggests installing jenssegers/mongodb-session (Add MongoDB session support to Laravel-MongoDB)
jenssegers/mongodb suggests installing jenssegers/mongodb-sentry (Add Sentry support to Laravel-MongoDB)
Writing lock file
Generating optimized autoload files

enter image description here

composer require jenssegers/mongodb --ignore-platform-reqs It solved my problem.

Kalpesh Gamit
  • 939
  • 1
  • 11
  • 30
9

Install PHP extension by running this command on your terminal.

sudo pecl install mongodb

At the end, you will see following information.

Build process completed successfully
Installing '/usr/local/Cellar/php/7.3.3/pecl/20180731/mongodb.so'
install ok: channel://pecl.php.net/mongodb-1.5.3
Extension mongodb enabled in php.ini

and then restart your PHP service.

Izhari Ishak Aksa
  • 858
  • 10
  • 13
3

Please check if mongodb modules is installed

php -m

Go to the installation directory and run the below command ( it will take some time)

composer require mongodb/mongodb --ignore-platform-reqs

This will ignore the MongoDB required packages & rest will be installed.

If you want the MongoDB Module to be installed then execute the below command

sudo apt-get install php-mongodb

Ninja Man
  • 86
  • 3
2

This error will happen when using WAMP as there is an unique php.ini for WAMP and CMD.

So you might have added the mongo-ext to your WAMP php.ini and so it looks as though it is running and included in the enabled extension's list. However, this is not available to the command line php.ini and also you need to confirm the CMD version of PHP you are running

  • You can confirm your CMD PHP version in the windows ENV variable "path"
  • If the CMD php version is not the same as the version you have included your mongo-ext, you will have to either install the mongo-ext into that version of PHP or change your path variable to point to the version of PHP you are currently using
  • Then ensure that the extension=php_mongodb is setup in both your WAMP and CMD version of php.ini

In order to confirm you have been successful your mongo-ext will show in your phpinfo() and if you run php -m on the CMD it will show in the rendered list

composer require jenssegers/mongodb --ignore-platform-reqs

The above is not the correct way to do it, as it will create problems into the future with other packages, updates and/or installs.

-1

To fix this issue on Windows, you need to download the correct DLL file and configure it properly in your PHP environment. Here's a step-by-step guide to help you resolve the problem:

  1. Check PHP Version: First, determine your PHP version by running the following command in your Command Prompt or Terminal:

    php -v
    

    Take note of the PHP version, as you'll need this information in the next steps.

  2. Identify Architecture and Thread Safety: Next, check if the Thread Safety (TS) is enabled or disabled. Run the following command:

    php -i | findstr "Thread Safety"
    

    If "Thread Safety" is enabled, you have a thread-safe (TS) version.

  3. Download the Correct DLL File: Now, visit the project's » Github releases page (https://github.com/mongodb/mongo-php-driver/releases) and look for the appropriate archive that matches your PHP version, architecture, and thread safety.

    For example, if you have PHP 8.2, x64 architecture, and TS enabled, the correct file would be named something like php_mongodb-1.x.8.2-ts-x64.zip. Make sure to choose the exact combination that matches your PHP environment.

  4. Copy DLL to PHP Extension Directory: After downloading extract and copy the DLL file to your PHP extension directory. By default, the extension directory is named "ext" and is located within your PHP installation folder (e.g., C:\php\ext on Windows).

  5. Update php.ini: Open your PHP configuration file (php.ini) and add the following line at the end:

    extension=php_mongodb
    

    Save the php.ini file after making the change.

  6. Restart Web Server: Finally, restart your web server (e.g., Wamp) to apply the changes.

Abdelhk
  • 55
  • 4