WebP Enabling for PHP GD Library
To have the Drupal module for WebP working with PHP GD enabled. I pulled my hair out trying to find support online for how to enable this easily on our Jelastic platform. Turns out that there’s no easy way. You need to rebuild GD library in PHP with the right support for your environment. PHP will bundle the GD library with environment specific paths, or at least that’s my assumption after what I saw inspecting the binary .so file, I could be wrong.
This GD building for PHP is tested on a CentOs 7 server.
- ### AS ROOT ###
- yum install libwebp-devel libwebp autoconf automake gcc libjpeg-devel libpng-devel libXpm-devel freetype-devel
Run PHP build stuff, you need to of course tweak the following to suit your php version:
- ### AS NON ROOT ###
- wget https://www.php.net/distributions/php-7.2.28.tar.bz2
- tar xf php-7.2.28.tar.bz2
- cd php-7.2.28
- cd ext/gd/
- ## Run the actual configure
- ## Copy new gd.so file in place, backup old one
- cp /usr/lib64/php/modules/gd.so ~/gd.so.bak
- cp /var/www/php-7.2.28/ext/gd/modules/gd.so /usr/lib64/php/modules/gd.so
- # Right after, otherwise server goes down.
- sudo service httpd restart
- # Check if WebP support is enabled:
- php -r "print_r( gd_info() );"
Clean up, delete dependencies:
yum remove gcc libpng-devel libjpeg-devel libXpm-devel g++ xorg-x11-proto-devel.noarch glibc-devel
Hope this helps.