user1729972
user1729972

Reputation: 896

How do I compile PHP with freetype support on Ubuntu 20.04

On calling the function imagettfbbox(), I'm getting the error

Fatal error: Uncaught Exception: Function "imagettfbbox" does not exist: check your FreeType installation in...

I understand from many sources, including other stackoverflow questions and PHP manual that I need to compile PHP with freetype support.

My challenge is I do not know exactly how to go about this. Manual says:

To enable support for FreeType 2 add --with-freetype-dir=DIR

Where is this flag to be set?

More importantly, how do I go from my existing set up (detailed following) to this stage?

Set-up (running in a container built off the php7.3.33-apache official image)

In essence, my PHP is pre-compiled. How do I replace this with my own re-compilation as the manual seems to be saying.

Upvotes: 1

Views: 1290

Answers (1)

Emanuele Bosimini
Emanuele Bosimini

Reputation: 101

The problems are known but they do not provide a satisfactory solution for both mine and your cases:

[1] freetype-config issues in Ubuntu 20.04: https://github.com/mapnik/mapnik/issues/4152

[2] gd issues with php-7.3 and Ubuntu 20.04:
https://github.com/docker-library/php/issues/865#issuecomment-511163936

If you're running PHP with Docker, the link [2] provides an elegant solution to this problem, which I believe is the best one.

However, given your perplexities, the previously mentioned thread is not suited to your situation.

I've found a solution:

  1. Obtain a copy of freetype-config from the provided link: https://gist.github.com/kaisersource/77ecb5979e05bd51c7f4994b8f99337d

  2. Copy the script in a directory that contains executable programs e.g. /usr/local/bin

  3. Download the PHP 7.3 source code from the official website https://www.php.net/distributions/php-7.3.33.tar.bz2 and compile it from source.

  4. Unzip the package and navigate to the folder that contains the source code

  5. Configure the build by running the following command: ./configure [your additional flags] --with-freetype-dir=/usr/include/freetype2 The directory may vary depending on the operating system

  6. Compile the source code by running the following command: make

  7. Install PHP 7.3 by running the following command: make install

This workaround should work for php versions lower than 7.3 as well. I have also tested with php 7.2.

For versions higher than php 7.4 there shouldn't be issues as it relies on pkg-config, as you can see from the manual

https://www.php.net/manual/en/image.installation.php

Hope it helps

Upvotes: 0

Related Questions