首页 > 解决方案 > Heroku 上的 Laravel/Vue.js 应用程序和 MongoDB 部署错误

问题描述

我正在尝试在 Heroku 上部署我的 Laravel/Vue.js 应用程序,但是当我尝试推送时出现错误。

这是错误消息:


       > Illuminate\Foundation\ComposerScripts::postAutoloadDump

       > @php artisan package:discover --ansi


       In DatabaseManager.php line 152:
                           

         Database connection [mysql] not configured.  


       Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1

 !     WARNING: A post-autoload-dump script terminated with an error

 !     ERROR: Dependency installation failed!

 !     

 !     The 'composer install' process failed with an error. The cause

 !     may be the download or installation of packages, or a pre- or

 !     post-install hook (e.g. a 'post-install-cmd' item in 'scripts')

 !     in your 'composer.json'.

 !     

 !     Typical error cases are out-of-date or missing parts of code,

 !     timeouts when making external connections, or memory limits.

 !     

 !     Check the above error output closely to determine the cause of

 !     the problem, ensure the code you're pushing is functioning

 !     properly, and that all local changes are committed correctly.

 !     

 !     For more information on builds for PHP on Heroku, refer to

 !     https://devcenter.heroku.com/articles/php-support

 !     

 !     REMINDER: the following warnings were emitted during the build;

 !     check the details above, as they may be related to this error:

 !     - A post-autoload-dump script terminated with an error

 !     Push rejected, failed to compile PHP app.

 !     Push failed

我正在使用 MongoDB,并且我已经配置了我的config/database.php和我的.env

config/database.php

'default' => env('DB_CONNECTION', 'mongodb'),
[...]
'connections' => [

        'mongodb' => [
            'driver'   => 'mongodb',
            'host' => env('MONGO_DB_HOST', '127.0.0.1'),
            'port' => env('MONGO_DB_PORT', '27017'),
            'username' => env('MONGO_DB_USERNAME', 'username'),
            'password' => env('MONGO_DB_PASSWORD', 'pwd'),
            'database' => env('MONGO_DB_DATABASE', 'name'),
            'options' => [
                'database' => 'admin'
            ],
            'dsn' => env('BD_DNS', 'dns')
        ],

    ],

.env

DB_CONNECTION=mongodb
DB_DNS=dns
MONGO_DB_HOST=127.0.0.1
MONGO_DB_PORT=27017
MONGO_DB_DATABASE=name
MONGO_DB_USERNAME=username
MONGO_DB_PASSWORD=pwd

我正在使用jenssegers/mongodb并添加"ext-mongodb": "*"到我的composer.json

{
   "name": "laravel/laravel",
   "type": "project",
   "description": "The Laravel Framework.",
   "keywords": [
       "framework",
       "laravel"
   ],
   "license": "MIT",
   "require": {
       "php": "^7.2.5",
       "fideloper/proxy": "^4.2",
       "fruitcake/laravel-cors": "^1.0",
       "guzzlehttp/guzzle": "^6.3",
       "jenssegers/mongodb": "3.7.x",
       "laravel/framework": "^7.0",
       "laravel/tinker": "^2.0",
       "laravel/ui": "2.4",
       "tymon/jwt-auth": "^1.0",
       "ext-mongodb": "*"
   },
   "require-dev": {
       "facade/ignition": "^2.0",
       "fzaninotto/faker": "^1.9.1",
       "mockery/mockery": "^1.3.1",
       "nunomaduro/collision": "^4.1",
       "phpunit/phpunit": "^8.5"
   },
   "config": {
       "optimize-autoloader": true,
       "preferred-install": "dist",
       "sort-packages": true
   },
   "extra": {
       "laravel": {
           "dont-discover": []
       }
   },
   "autoload": {
       "psr-4": {
           "App\\": "app/"
       },
       "classmap": [
           "database/seeds",
           "database/factories"
       ]
   },
   "autoload-dev": {
       "psr-4": {
           "Tests\\": "tests/"
       }
   },
   "minimum-stability": "dev",
   "prefer-stable": true,
   "scripts": {
       "post-root-package-install": [
           "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
       ],
       "post-autoload-dump": [
           "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
           "@php artisan package:discover --ansi"
       ],
       "post-create-project-cmd": [
           "@php artisan key:generate --ansi"
       ]
   }
}

最后,这是我的Procfileweb: $(composer config bin-dir)/heroku-php-nginx -C nginx.conf public/

php artisan config:cache在尝试再次推送之前已经运行,但我遇到了同样的错误。谁能帮我解决这个问题?为什么我的 MongoDB 连接配置不正确?

预先感谢 !

标签: laravelmongodbvue.jsheroku

解决方案


问题已解决:我的一个文件中仍有一个mysql呼叫:在我的config/queue.php文件末尾

我改变了这个:

[...] 
    'failed' => [
            'driver' => env('QUEUE_FAILED_DRIVER', 'database'),
            'database' => env('DB_CONNECTION', 'mysql'),
            'table' => 'failed_jobs',
        ],
];

对此:

[...]    
'failed' => [
            'driver' => env('QUEUE_FAILED_DRIVER', 'database'),
            'database' => env('DB_CONNECTION', 'mongodb'),
            'table' => 'failed_jobs',
        ],
];

推荐阅读