gpt4 book ai didi

laravel - 在 Laravel Sail 8.0 环境中安装 Jenssegers/MongoDB

转载 作者:行者123 更新时间:2023-12-04 12:05:11 24 4
gpt4 key购买 nike

因此,我设法使用 WSL2 在 Windows 中全新安装了 Laravel。我的项目的需求之一是有两个数据库同时运行mysql和mongodb。
我在我的 docker-compose.yml 中添加了 MongoDB 的图像,因为dock-hub 告诉我,但是当我尝试添加 jenssegers/laravel-mongodb 包时,sail 告诉我我没有正确的要求。
如何正确连接两个容器,以便我可以毫无问题地安装软件包?
日志:

~/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.
我的 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

最佳答案

我设法安装了这个包:3 首先我通过运行这个命令提取 Docker 配置

php artisan sail:publish
然后编辑文件 docker/8.0/Dockerfile , 在 RUN apt- 后面添加以下几行一
RUN pecl install mongodb

RUN echo "extension=mongodb.so" > /etc/php/8.0/cli/php.ini
保存它,然后运行这个命令来重建 docker
sail build --no-cache

关于laravel - 在 Laravel Sail 8.0 环境中安装 Jenssegers/MongoDB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65279682/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com