Laravel5.4+Image Intervention在Heroku用S3传图遇GD库缺失问题
Hey there, I’ve run into this exact GD Library issue on Heroku before—let’s walk through the fixes that worked for me and other developers:
1. Double-check your composer.json configuration
Just adding "ext-gd": "*" might not be enough if Heroku needs explicit platform context. Try updating your composer.json to include a platform section that matches your app’s PHP version:
{ "require": { "aws/aws-sdk-php": "~2.6", "ext-gd": "*" }, "config": { "platform": { "php": "7.4", // Replace with your app's actual PHP version (e.g., 8.1) "ext-gd": "7.4" } } }
This tells Heroku’s PHP buildpack exactly which version of the extension to install, avoiding version mismatches that can block installation.
2. Ensure you’re using the official Heroku PHP buildpack
If you’ve switched to a custom buildpack or have an outdated one configured, it might not handle GD extension installation properly. Reset to the official buildpack with:
heroku buildpacks:set heroku/php
Then redeploy your changes to apply the update:
git add composer.json git commit -m "Configure GD extension and set official PHP buildpack" git push heroku main
3. Verify GD is installed post-deployment
After redeploying, confirm if GD actually made it into your environment. Run this command to access your app’s console:
heroku run php -m
Look for gd in the list of installed extensions. If it’s missing, check your build logs for errors that might explain the failure:
heroku logs --tail
Scan for lines related to "ext-gd" or "GD Library"—you might catch issues like missing system dependencies (rare on Heroku, but possible for older PHP versions).
4. Clear Heroku’s build cache
Sometimes cached dependencies can prevent new extensions from being installed. Force a full cache clear with:
heroku config:set CLEAR_CACHE=true git commit -m "Trigger full cache clear" --allow-empty git push heroku main
This will rebuild your app from scratch, ensuring all required extensions are installed fresh without leftover cache conflicts.
If none of these steps work, double-check that your PHP version is compatible with GD (all supported PHP versions on Heroku include GD support, so this is unlikely). You could also try specifying a specific minimum version of ext-gd instead of "*" (e.g., "ext-gd": ">=7.4").
内容的提问来源于stack exchange,提问作者Lv007

