Fixing PHP Startup: Unable to load dynamic library 'gd.so'
Update 20/04/2020: I just realised there were a couple of mistakes and have corrected it. Also updated to note of my system specification
Notice: This was done on a Ubuntu 16.04 machine with PHP 7.2 and NGINX. If you're using other configs, it might or might not work.
Earlier*, I encountered an annoying problem with one of PHP's extension, PHP GD. No matter how many times or what version of PHP GD I installed, PHP always prints the following warning:
PHP Warning: PHP Startup: Unable to load dynamic library 'gd.so' (tried: /usr/lib/php/20170718/gd.so (/usr/lib/php/20170718/gd.so: undefined symbol: gdImageCreateFromWebp), /usr/lib/php/20170718/gd.so.so (/usr/lib/php/20170718/gd.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
Thanks to this, here's how I fixed it for PHP7.2-FPM:
- Remove PHP GD including any reference/config to it. Run
sudo apt purge php7.2-gd
. - Reinstall the extension:
sudo apt update && sudo apt install php7.2-gd
. - Make sure
gd.ini
exist in your PHP 'mods-available' directory. For most, that would be at/etc/php/7.2/mods-available
. If not, create it with the following content:
; configuration for php gd module
; priority=20
extension=gd.so
- Go to
/usr/local/lib
. The culprits are the multiple libgd*.so files. There's only supposed to be one, that islibgd.so
.
5. Either delete the files in red, or move them to a backup folder, leaving only libgd.so
.
6. Restart both PHP and NGINX: service php7.2-fpm restart && service nginx restart
7. Verify that it's enabled and loaded by PHP:
* Actually the warning for it has appeared since several months ago, I just didn't have time to take a look at it, since it didn't break anything.