Dokku:部署 Laravel 应用程序时缺少 PHP 扩展 mbstring

Dokku: PHP extension mbstring is missing when deploying Laravel application

我仍然在下面收到这个错误,说在使用 Dokku(版本 0.18.3) 即使我遵循了文档 (https://devcenter.heroku.com/articles/php-support#using-optional-extensions).

-----> Cleaning up...
-----> Building laravel-app from herokuish...
-----> Adding BUILD_ENV to build environment...
-----> Warning: Multiple default buildpacks reported the ability to handle this app. The first buildpack in the list below will be used.
       Detected buildpacks: multi nodejs php
-----> Multipack app detected
=====> Downloading Buildpack: https://github.com/heroku/heroku-buildpack-php.git
=====> Detected Framework: PHP
remote: -----> Bootstrapping...
remote: -----> Installing platform packages...
remote:        - php (7.4.3)
remote:        - ext-mbstring (bundled with php)
remote:        - apache (2.4.41)
remote:        - nginx (1.16.1)
remote: PHP Warning:  PHP Startup: Unable to load dynamic library 'mbstring.so' (tried: /app/.heroku/php/lib/php/extensions/no-debug-non-zts-20190902/mbstring.so (libonig.so.4: cannot open shared object file: No such file or directory), /app/.heroku/php/lib/php/extensions/no-debug-non-zts-20190902/mbstring.so.so (/app/.heroku/php/lib/php/extensions/no-debug-non-zts-20190902/mbstring.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
remote: PHP Warning:  PHP Startup: Unable to load dynamic library 'mbstring.so' (tried: /app/.heroku/php/lib/php/extensions/no-debug-non-zts-20190902/mbstring.so (libonig.so.4: cannot open shared object file: No such file or directory), /app/.heroku/php/lib/php/extensions/no-debug-non-zts-20190902/mbstring.so.so (/app/.heroku/php/lib/php/extensions/no-debug-non-zts-20190902/mbstring.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
remote: -----> Installing dependencies...
remote:        Composer version 1.9.3 2020-02-04 12:58:49
remote:        PHP Warning:  PHP Startup: Unable to load dynamic library 'mbstring.so' (tried: /app/.heroku/php/lib/php/extensions/no-debug-non-zts-20190902/mbstring.so (libonig.so.4: cannot open shared object file: No such file or directory), /app/.heroku/php/lib/php/extensions/no-debug-non-zts-20190902/mbstring.so.so (/app/.heroku/php/lib/php/extensions/no-debug-non-zts-20190902/mbstring.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
remote:        Loading composer repositories with package information
remote:        Installing dependencies from lock file
remote:        Your requirements could not be resolved to an installable set of packages.
remote:        
remote:          Problem 1
remote:            - The requested PHP extension ext-mbstring * is missing from your system. Install or enable PHP's mbstring extension.
remote:          Problem 2
remote:            - Installation request for laravel/framework v6.17.1 -> satisfiable by laravel/framework[v6.17.1].
remote:            - laravel/framework v6.17.1 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.
remote:          Problem 3
remote:            - Installation request for league/commonmark 1.3.1 -> satisfiable by league/commonmark[1.3.1].
remote:            - league/commonmark 1.3.1 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.
remote:          Problem 4
remote:            - Installation request for sentry/sentry 2.3.1 -> satisfiable by sentry/sentry[2.3.1].
remote:            - sentry/sentry 2.3.1 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.
remote:          Problem 5
remote:            - laravel/framework v6.17.1 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.
remote:            - sentry/sentry-laravel 1.7.0 requires illuminate/support 5.0 - 5.8 | ^6.0 | ^7.0 -> satisfiable by laravel/framework[v6.17.1].
remote:            - Installation request for sentry/sentry-laravel 1.7.0 -> satisfiable by sentry/sentry-laravel[1.7.0].
remote:        
remote:          To enable extensions, verify that they are enabled in your .ini files:
remote:            - /app/.heroku/php/etc/php/php.ini
remote:            - /app/.heroku/php/etc/php/conf.d/000-heroku.ini
remote:            - /app/.heroku/php/etc/php/conf.d/010-ext-zend_opcache.ini
remote:            - /app/.heroku/php/etc/php/conf.d/100-ext-mbstring.ini
remote:            - /tmp/buildpackKITei/conf/php/apm-nostart-overrides/apm-nostart-overrides.ini
remote:          You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.
remote: 
remote:  !     ERROR: Dependency installation failed!
remote:  !     
remote:  !     The 'composer install' process failed with an error. The cause
remote:  !     may be the download or installation of packages, or a pre- or
remote:  !     post-install hook (e.g. a 'post-install-cmd' item in 'scripts')
remote:  !     in your 'composer.json'.
remote:  !     
remote:  !     Typical error cases are out-of-date or missing parts of code,
remote:  !     timeouts when making external connections, or memory limits.
remote:  !     
remote:  !     Check the above error output closely to determine the cause of
remote:  !     the problem, ensure the code you're pushing is functioning
remote:  !     properly, and that all local changes are committed correctly.
remote:  !     
remote:  !     For more information on builds for PHP on Heroku, refer to
remote:  !     https://devcenter.heroku.com/articles/php-support
remote: 

我尝试过的:

  1. 更新composer.json
{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": [
        "framework",
        "laravel"
    ],
    "license": "MIT",
    "require": {
        "php": "^7.2",
        "ext-mbstring": "*",
        "aws/aws-sdk-php": "^3.133",
        "fideloper/proxy": "^4.0",
        "laravel/framework": "^6.2",
        "laravel/tinker": "^2.0",
        "sentry/sentry-laravel": "^1.6"
    },
    "require-dev": {
        "facade/ignition": "^1.4",
        "fzaninotto/faker": "^1.9.1",
        "mockery/mockery": "^1.0",
        "nunomaduro/collision": "^3.0",
        "phpunit/phpunit": "^8.0"
    },
    "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-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"
        ]
    }
}
  1. 运行 composer update
  2. git addgit commit composer.jsoncomposer.lock 文件,然后部署

感谢任何帮助,谢谢!

问题已解决,步骤如下:

  1. 确保您的应用使用这 2 个构建包:
https://github.com/heroku/heroku-buildpack-apt
https://github.com/heroku/heroku-buildpack-php
  1. 在根目录创建一个新文件Aptfile,内容如下:
libonig-dev
libonig4
  1. git addgit commit 并部署,现在应该可以工作了

参考文献:

  1. 答案参考和更多详细信息:https://github.com/gliderlabs/herokuish/issues/529#issuecomment-592938477
  2. https://github.com/heroku/heroku-buildpack-apt
  3. https://github.com/heroku/heroku-buildpack-php
  4. 如何 set/add 在 dokku 中构建包:https://github.com/dokku/dokku/blob/master/docs/deployment/methods/buildpacks.md
  5. 关于Aptfilehttps://elements.heroku.com/buildpacks/heroku/heroku-buildpack-apt