PHP7.2 装mongodb 遇到的坑,完美解决!


公司要做QA安全测试,组长就丢了一个源码包给我,什么资料都无。

系统是个Laravel框架,源码都是从线上git下来。然后看了本地composer.json 没有生成vendor

第一步安装 composer.phar,让它可以识别composer.json

下载地址:https://mirrors.aliyun.com/composer/composer.phar?spm=a2c6h.265751.1380423.3.29eb26212br7dB&file=composer.phar

下载后放到项目根目录:

然后执行一下

php composer.phar

进行安装

composer install

composer.json文件代码如下:

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": [
        "framework",
        "laravel"
    ],
    "license": "MIT",
    "require": {
        "php": "^7.2",
        "darkaonline/l5-swagger": "6.0.*",
        "fideloper/proxy": "^4.0",
        "fruitcake/laravel-cors": "^1.0",
        "gregwar/captcha": "^1.1",
        "guzzlehttp/guzzle": "^6.5",
        "johnlui/aliyun-oss": "^2.2",
        "laravel/framework": "^6.0",
        "laravel/tinker": "^1.0",
        "lcobucci/jwt": "^3.3",
        "maatwebsite/excel": "^3.1",
        "mongodb/mongodb": "^1.4.2",
        "phpoffice/phpspreadsheet": "^1.11",
        "predis/predis": "^1.1",
        "zgldh/qiniu-laravel-storage": "^0.10.3"
    },
    "require-dev": {
        "facade/ignition": "^1.4",
        "fzaninotto/faker": "^1.4",
        "mnabialek/laravel-sql-logger": "^2.2",
        "mockery/mockery": "^1.0",
        "nunomaduro/collision": "^3.0",
        "phpunit/phpunit": "^8.0",
        "rap2hpoutre/laravel-log-viewer": "^1.6"
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "autoload": {
        "files": [
            "app/helpers.php"
        ],
        "psr-4": {
            "App\\": "app/"
        },
        "classmap": [
            "database/seeds",
            "database/factories"
        ]
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    },
    "repositories": {
        "packagist": {
            "type": "composer",
            "url": "https://mirrors.aliyun.com/composer/"
        }
    }
}

 其实能安装成功完全要看这里了:PHP本地版本:PHP Version 7.2.13 Mongodb版本要选1.53,否则就等着被虐吧。

原文地址:https://www.cnblogs.com/chaihtml/p/11183348.html

php开启mongodb扩展

1、

 打开phpinfo 查看 nts(非线程) 还是 ts (线程),操作位数;

下载对应的版本的php_mongodb.dll 文件

下载链接:https://pecl.php.net/package/mongodb/1.2.9/windows

 把文件解压出来 php_mongodb.dll 文件复制到php安装目录下的 ext 目录下(列子: phpStudy\php\php-7.1.13-nts\ext)

 打开php.ini 配置文件增加行 : extension=php_mongodb.dll

 php 7.2 适用网址 :https://windows.php.net/downloads/pecl/releases/mongodb/

 重启,再打开phpinfo() 查看是否有mongodb扩展,出现下图则安装成功

只要Mongodb扩展能识别了,composer install 才能把 composer.json 里面的laravel依赖的 jenssegers/mongodb安装好

 一般装好后,会生成composer.lock,防止重复安装,如果install composer不能运行,就要手动删除这个composer.lock文件。

分享代码只是为了让大家少走弯路,所以我尽量写详细文档。看过的觉得能解决问题的,也可以点赞推荐一下。