HerokuにPHP8.0のLaravelプロジェクトをデプロイしようとすると、次のようなエラーが発生しました。どうもPHP8.1として認識されているようです。
$ git push heroku main
Enumerating objects: 114, done.
Counting objects: 100% (114/114), done.
Compressing objects: 100% (95/95), done.
Writing objects: 100% (114/114), 63.67 KiB | 2.36 MiB/s, done.
Total 114 (delta 11), reused 0 (delta 0), pack-reused 0
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Building on the Heroku-20 stack
remote: -----> Using buildpack: heroku/php
remote: -----> PHP app detected
remote: -----> Bootstrapping...
remote: -----> Installing platform packages...
remote: - php (8.1.1)
remote: - ext-mbstring (bundled with php)
remote: - composer (2.1.14)
remote: - apache (2.4.51)
remote: - nginx (1.20.2)
remote: -----> Installing dependencies...
:(中略)
remote: In Collection.php line 11:
remote:
remote: During inheritance of ArrayAccess: Uncaught ErrorException: Return type of
remote: Illuminate\Support\Collection::offsetExists($key) should either be compatib
remote: le with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTyp
remote: eWillChange] attribute should be used to temporarily suppress the notice in
remote: /tmp/build_ef269800/vendor/laravel/framework/src/Illuminate/Support/Collec
remote: tion.php:1277
remote: Stack trace:
remote: #0 /tmp/build_ef269800/vendor/laravel/framework/src/Illuminate/Support/Coll
remote: ection.php(11): Illuminate\Foundation\Bootstrap\HandleExceptions->handleErr
remote: or()
remote: #1 /tmp/build_ef269800/vendor/composer/ClassLoader.php(571): include('...')
remote: #2 /tmp/build_ef269800/vendor/composer/ClassLoader.php(428): Composer\Autol
remote: oad\includeFile()
remote: #3 /tmp/build_ef269800/vendor/laravel/framework/src/Illuminate/Support/help
remote: ers.php(109): Composer\Autoload\ClassLoader->loadClass()
remote: #4 /tmp/build_ef269800/vendor/laravel/framework/src/Illuminate/Foundation/P
remote: ackageManifest.php(130): collect()
remote: #5 /tmp/build_ef269800/vendor/laravel/framework/src/Illuminate/Foundation/P
remote: ackageManifest.php(106): Illuminate\Foundation\PackageManifest->build()
remote: #6 /tmp/build_ef269800/vendor/laravel/framework/src/Illuminate/Foundation/P
remote: ackageManifest.php(89): Illuminate\Foundation\PackageManifest->getManifest(
remote: )
remote: #7 /tmp/build_ef269800/vendor/laravel/framework/src/Illuminate/Foundation/P
remote: ackageManifest.php(78): Illuminate\Foundation\PackageManifest->config()
remote: #8 /tmp/build_ef269800/vendor/laravel/framework/src/Illuminate/Foundation/B
remote: ootstrap/RegisterFacades.php(26): Illuminate\Foundation\PackageManifest->al
remote: iases()
remote: #9 /tmp/build_ef269800/vendor/laravel/framework/src/Illuminate/Foundation/A
remote: pplication.php(219): Illuminate\Foundation\Bootstrap\RegisterFacades->boots
remote: trap()
remote: #10 /tmp/build_ef269800/vendor/laravel/framework/src/Illuminate/Foundation/
remote: Console/Kernel.php(320): Illuminate\Foundation\Application->bootstrapWith()
remote: #11 /tmp/build_ef269800/vendor/laravel/framework/src/Illuminate/Foundation/
remote: Console/Kernel.php(129): Illuminate\Foundation\Console\Kernel->bootstrap()
remote: #12 /tmp/build_ef269800/artisan(37): Illuminate\Foundation\Console\Kernel->
remote: handle()
remote: #13 {main}
remote:
remote:
remote: Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 255
remote: ! WARNING: A post-autoload-dump script terminated with an error
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: !
remote: ! REMINDER: the following warnings were emitted during the build;
remote: ! check the details above, as they may be related to this error:
remote: ! - A post-autoload-dump script terminated with an error
remote:
remote: ! Push rejected, failed to compile PHP app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to mysterious-forest-47676.
remote:
To https://git.heroku.com/mysterious-forest-47676.git
! [remote rejected] main -> main (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/mysterious-forest-47676.git'
解決策
composer.jsonとcomposer.lockのphpバージョンを~8.0.0に変更します。
(composer.json)
"require": {
"php": "^7.2.5|~8.0.0",
"fideloper/proxy": "^4.4",
"laravel/framework": "^6.20.26",
"laravel/tinker": "^2.5",
"laravel/ui": "1.*"
},
(composer.lock)
"require": {
"php": "^7.2 || ~8.0.0"
},
PHPのバージョンを変更後、git push heroku mainを実行するとデプロイに成功しました。php (8.0.14)として認識されているのがわかります。
$ git push heroku main
Enumerating objects: 118, done.
Counting objects: 100% (118/118), done.
Compressing objects: 100% (99/99), done.
Writing objects: 100% (118/118), 63.93 KiB | 1.94 MiB/s, done.
Total 118 (delta 15), reused 0 (delta 0), pack-reused 0
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Building on the Heroku-20 stack
remote: -----> Using buildpack: heroku/php
remote: -----> PHP app detected
remote: -----> Bootstrapping...
remote:
remote: ! WARNING: Your 'composer.lock' is out of date!
remote: !
remote: ! The 'composer.lock' file in your project is not up to date with
remote: ! the main 'composer.json' file. This may result in installation
remote: ! of incorrect packages or package versions.
remote: !
remote: ! The lock file is required in order to guarantee reliable and
remote: ! reproducible installation of dependencies across systems and
remote: ! deploys. It must always be kept in sync with 'composer.json'.
remote: !
remote: ! Whenever you change 'composer.json', ensure that you perform
remote: ! the following steps locally on your computer:
remote: ! 1) run 'composer update'
remote: ! 2) add all changes using 'git add composer.json composer.lock'
remote: ! 3) commit using 'git commit'
remote: !
remote: ! Ensure that you updated the lock file correctly, and that you
remote: ! ran 'git add' on both files, before deploying again.
remote: !
remote: ! Please remember to always keep your 'composer.lock' updated in
remote: ! lockstep with 'composer.json' to avoid common problems related
remote: ! to dependencies during collaboration and deployment.
remote: !
remote: ! Please refer to the Composer documentation for further details:
remote: ! https://getcomposer.org/doc/
remote: ! https://getcomposer.org/doc/01-basic-usage.md
remote:
remote: -----> Installing platform packages...
remote: - php (8.0.14)
remote: - ext-mbstring (bundled with php)
remote: - composer (2.1.14)
remote: - apache (2.4.51)
remote: - nginx (1.20.2)
:(中略)
remote: Verifying deploy... done.
To https://git.heroku.com/mysterious-forest-47676.git
* [new branch] main -> main