On Amazon Linux 2 for elastic beanstalk php, it comes with freetype 2.3.11 which doesn't render fonts correct for my project so I downloaded freetype 2.10.1 and built without/with harfbuzz according to http://www.linuxfromscratch.org/blfs/view/svn/general/freetype2.html. Then I compiled the php gd extension as follows.
cd php-7.2.19/ext/gd
phpize
./configure --with-php-config=/usr/bin/php-config --with-gd --with-freetype-dir=/usr --with-png-dir=/usr --with-xpm-dir=/usr --with-webp-dir=/usr
make
sudo cp modules/gd.so /usr/lib64/php/7.2/modules/
but when I run php -v I get "PHP Warning: PHP Startup: Unable to load dynamic library 'gd.so' (tried: /usr/lib64/php/7.2/modules/gd.so (/usr/lib64/php/7.2/modules/gd.so: undefined symbol: php_gd_gdImageJpegCtx), /usr/lib64/php/7.2/modules/gd.so.so (/usr/lib64/php/7.2/modules/gd.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0"