Enable FreeType and recompile PHP on Linux

FreeType library is typically required along with GD library in PHP. This will enable usage of imagettftext() and other functions.

Install FreeType

Install FreeType library first at OS level.

yum install freetype-devel

You have to add the installed path to the PHP configure command.. FreeType will be installed in /usr/include/freetype2 on RHEL.

find / -name freetype

Enable FreeType in PHP

You have to get the configure command first. Use php -i | grep “Configure” command and get the configure command. It will be something like this.

./configure  –prefix=/usr/local/php7 –with-mysqli=/usr/bin/mysql_config –with-apxs2=/usr/local/apache2/bin/apxs –with-config-file-path=/usr/local/apcahe2/conf –with-libdir=lib64 –with-openssl –with-zlib-dir=/usr/lib –with-gd –with-gettext –with-ldap –with-mcrypt –with-mysql –enable-soap –with-imap –enable-zip –with-pdo-mysql –with-kerberos –with-imap-ssl –with-curl –enable-mbstring php_sapis=cli


To the end, add this.

–with-freetype-dir=/usr/include/freetype2 –enable-gd-native-ttf

So your complete configure command will look like below.

./configure  –prefix=/usr/local/php7 –with-mysqli=/usr/bin/mysql_config –with-apxs2=/usr/local/apache2/bin/apxs –with-config-file-path=/usr/local/apcahe2/conf –with-libdir=lib64 –with-openssl –with-zlib-dir=/usr/lib –with-gd –with-gettext –with-ldap –with-mcrypt –with-mysql –enable-soap –with-imap –enable-zip –with-pdo-mysql –with-kerberos –with-imap-ssl –with-curl –enable-mbstring php_sapis=cli –with-freetype-dir=/usr/include/freetype2 –enable-gd-native-ttf

After executing this command in PHP directory, execute below commands

make clean
make install

Restart your Apache/Nginx server, if required.

You can check whether it is enabled or not in phpinfo();

Posted in php
error: Uh oh ...