Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing Jenssegers/MongoDB in a Laravel Sail 8.0 environment

So I've managed to do a clean install of Laravel in Windows using WSL2. One of the requirements of my project is to have two databases running at the same time mysql and mongodb.

I added an image of MongoDB in my docker-compose.yml as the dock-hub tells me, but when I try to add the jenssegers/laravel-mongodb package sail tells me I don't have the correct requirements.

How do I connect both containers properly, so I can install the package without any issues?

Logs:

~/example-app$ sail composer require jenssegers/mongodb:"^3.8"
./composer.json has been updated
Running composer update jenssegers/mongodb
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

Problem 1
    - jenssegers/mongodb[v3.8.0, ..., v3.8.1] require mongodb/mongodb ^1.6 -> satisfiable by mongodb/mongodb[1.6.0, ..., 1.9.x-dev (alias of dev-master)].
    - mongodb/mongodb 1.9.x-dev is an alias of mongodb/mongodb dev-master and thus requires it to be installed too.
    - mongodb/mongodb[dev-master, 1.8.0-RC1, ..., v1.8.x-dev] require ext-mongodb ^1.8.1 -> it is missing from your system. Install or enable PHP's mongodb extension.
    - mongodb/mongodb[1.6.0, ..., v1.6.x-dev] require php ^5.6 || ^7.0 -> your php version (8.0.0) does not satisfy that requirement.
    - mongodb/mongodb[1.7.0-beta1, ..., v1.7.x-dev] require php ^7.0 -> your php version (8.0.0) does not satisfy that requirement.
    - Root composer.json requires jenssegers/mongodb ^3.8 -> satisfiable by jenssegers/mongodb[v3.8.0, v3.8.1].

To enable extensions, verify that they are enabled in your .ini files:
    - /etc/php/8.0/cli/php.ini
    - /etc/php/8.0/cli/conf.d/10-mysqlnd.ini
    - /etc/php/8.0/cli/conf.d/10-opcache.ini
    - /etc/php/8.0/cli/conf.d/10-pdo.ini
    - /etc/php/8.0/cli/conf.d/15-xml.ini
    - /etc/php/8.0/cli/conf.d/20-bcmath.ini
    - /etc/php/8.0/cli/conf.d/20-calendar.ini
    - /etc/php/8.0/cli/conf.d/20-ctype.ini
    - /etc/php/8.0/cli/conf.d/20-curl.ini
    - /etc/php/8.0/cli/conf.d/20-dom.ini
    - /etc/php/8.0/cli/conf.d/20-exif.ini
    - /etc/php/8.0/cli/conf.d/20-ffi.ini
    - /etc/php/8.0/cli/conf.d/20-fileinfo.ini
    - /etc/php/8.0/cli/conf.d/20-ftp.ini
    - /etc/php/8.0/cli/conf.d/20-gd.ini
    - /etc/php/8.0/cli/conf.d/20-gettext.ini
    - /etc/php/8.0/cli/conf.d/20-iconv.ini
    - /etc/php/8.0/cli/conf.d/20-igbinary.ini
    - /etc/php/8.0/cli/conf.d/20-imap.ini
    - /etc/php/8.0/cli/conf.d/20-intl.ini
    - /etc/php/8.0/cli/conf.d/20-ldap.ini
    - /etc/php/8.0/cli/conf.d/20-mbstring.ini
    - /etc/php/8.0/cli/conf.d/20-msgpack.ini
    - /etc/php/8.0/cli/conf.d/20-mysqli.ini
    - /etc/php/8.0/cli/conf.d/20-pdo_mysql.ini
    - /etc/php/8.0/cli/conf.d/20-pdo_pgsql.ini
    - /etc/php/8.0/cli/conf.d/20-pdo_sqlite.ini
    - /etc/php/8.0/cli/conf.d/20-pgsql.ini
    - /etc/php/8.0/cli/conf.d/20-phar.ini
    - /etc/php/8.0/cli/conf.d/20-posix.ini
    - /etc/php/8.0/cli/conf.d/20-readline.ini
    - /etc/php/8.0/cli/conf.d/20-redis.ini
    - /etc/php/8.0/cli/conf.d/20-shmop.ini
    - /etc/php/8.0/cli/conf.d/20-simplexml.ini
    - /etc/php/8.0/cli/conf.d/20-soap.ini
    - /etc/php/8.0/cli/conf.d/20-sockets.ini
    - /etc/php/8.0/cli/conf.d/20-sqlite3.ini
    - /etc/php/8.0/cli/conf.d/20-sysvmsg.ini
    - /etc/php/8.0/cli/conf.d/20-sysvsem.ini
    - /etc/php/8.0/cli/conf.d/20-sysvshm.ini
    - /etc/php/8.0/cli/conf.d/20-tokenizer.ini
    - /etc/php/8.0/cli/conf.d/20-xmlreader.ini
    - /etc/php/8.0/cli/conf.d/20-xmlwriter.ini
    - /etc/php/8.0/cli/conf.d/20-xsl.ini
    - /etc/php/8.0/cli/conf.d/20-zip.ini
    - /etc/php/8.0/cli/conf.d/25-memcached.ini
    - /etc/php/8.0/cli/conf.d/99-sail.ini
You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.

My docker-compose.yml

# For more information: https://laravel.com/docs/sail
version: '3'
services:
    laravel.test:
        build:
            context: ./vendor/laravel/sail/runtimes/8.0
            dockerfile: Dockerfile
            args:
                WWWGROUP: '${WWWGROUP}'
        image: sail-8.0/app
        ports:
            - '${APP_PORT:-80}:80'
        environment:
            WWWUSER: '${WWWUSER}'
            LARAVEL_SAIL: 1
        volumes:
            - '.:/var/www/html'
        networks:
            - sail
        depends_on:
            - mysql
            - mongo
            # - selenium

    # ...

    mysql:
        image: 'mysql:8.0'
        ports:
            - '${FORWARD_DB_PORT:-3306}:3306'
        environment:
            MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
            MYSQL_DATABASE: '${DB_DATABASE}'
            MYSQL_USER: '${DB_USERNAME}'
            MYSQL_PASSWORD: '${DB_PASSWORD}'
            MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
        volumes:
            - 'sailmysql:/var/lib/mysql'
        networks:
            - sail

    mongo:
        image: mongo
        restart: always
        environment:
            MONGO_INITDB_ROOT_USERNAME: root
            MONGO_INITDB_ROOT_PASSWORD: example

    mongo-express:
        image: mongo-express
        restart: always
        ports:
        - 8081:8081
        environment:
            ME_CONFIG_MONGODB_ADMINUSERNAME: root
            ME_CONFIG_MONGODB_ADMINPASSWORD: example    
networks:
    sail:
        driver: bridge
volumes:
    sailmysql:
        driver: local
    sailredis:
        driver: local
like image 415
Helena Avatar asked Dec 13 '20 19:12

Helena


People also ask

Can I use MongoDB with Laravel?

An Eloquent model and Query builder with support for MongoDB, using the original Laravel API. This library extends the original Laravel classes, so it uses exactly the same methods. Make sure you have the MongoDB PHP driver installed.

How many installs does Laravel eloquent have?

Installs : 4 843 374 Dependents : 201 Suggesters : 11 Security : 0 Stars : 5 673 Forks : 1 256 Open Issues : 118 This package is auto-updated. This package adds functionalities to the Eloquent model and Query builder for MongoDB, using the original Laravel API. This library extends the original Laravel classes, so it uses exactly the same methods.

Is it possible to do a clean install of Laravel using WSL2?

So I've managed to do a clean install of Laravel in Windows using WSL2. One of the requirements of my project is to have two databases running at the same time mysql and mongodb.

What is the use of Laravel sail in Docker?

Sail provides a great starting point for building a Laravel application using PHP, MySQL, and Redis without requiring prior Docker experience. At its heart, Sail is the docker-compose.yml file and the sail script that is stored at the root of your project.


1 Answers

I manage to install this package :3 First I extract Docker config, by run this command

php artisan sail:publish

then edit file docker/8.0/Dockerfile, add following lines after the RUN apt- one

RUN pecl install mongodb

RUN echo "extension=mongodb.so" > /etc/php/8.0/cli/php.ini

save it, then run this command to rebuild docker

sail build --no-cache
like image 84
l3lackheart Avatar answered Oct 07 '22 09:10

l3lackheart