需要 Heroku Laravel 4.2 Mcrypt PHP 扩展

Heroku Laravel 4.2 Mcrypt PHP extension required

我是 Heroku 的新手,我知道在 Whosebug 上已经有人问过很多类似的问题,但我找不到适合我的解决方案。

我在尝试部署我的 laravel 4.2 应用程序时遇到以下问题:

remote:        > php artisan clear-compiled
remote:        Mcrypt PHP extension required.
remote:        Script php artisan clear-compiled handling the post-install-cmd event returned with error code 1
remote:  !     Push rejected, failed to compile PHP app.

我尝试使用 heroku run bash 命令连接到 heroku 环境,但无法获得 mcrypt 扩展的状态,因为没有授予我 root 权限。

还尝试将 heroku buildpacks:set https://github.com/heroku/heroku-buildpack-php 设置为 buildpack。但是没有成功。

这是我的composer.json

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "require": {
        "laravel/framework": "4.2.*"
    },
    "autoload": {
        "classmap": [
            "app/commands",
            "app/library",
            "app/controllers",
            "app/models",
            "app/Lib.php",
            "app/database/migrations",
            "app/database/seeds",
            "app/tests/TestCase.php"
        ]
    },
    "scripts": {
        "post-install-cmd": [
            "php artisan clear-compiled",
            "php artisan optimize"
        ],
        "post-update-cmd": [
            "php artisan clear-compiled",
            "php artisan optimize"
        ],
        "post-create-project-cmd": [
            "php artisan key:generate"
        ]
    },
    "config": {
        "preferred-install": "dist"
    },
    "minimum-stability": "stable"
}

非常感谢任何帮助。

您尚未在 composer.json 中指定 PHP 版本或对 mcrypt 扩展的依赖。

首先取决于 PHP 的特定版本:

composer require php ~7.1.0

如果您愿意,可以将 ~7.1.0 替换为 ~7.0.0~5.6.0

Heroku includes mcrypt by default if you are using PHP 5.6. But if you're using 7.0 or 7.1 you'll need to add it:

composer require ext-mcrypt

然后通过 运行 composer update 更新您的 composer.lock。确保一切仍在本地按预期工作,然后提交更新的 composer.jsoncomposer.lock 文件并再次推送到 Heroku。

请注意 the mcrypt extension has been deprecated as of PHP 7.1. It is probably worth considering an upgrade to Laravel 5.1 or higher which replaces mcrypt with openssl,尤其是当您使用 PHP 7.1.

我在调用 composer update 时遇到了同样的错误。这是因为 composer 调用的 php 版本与 path 中可用的版本不同。将正确的 path 设置为相同版本的 php 解决了问题。