How to Fix Configure: Error: png.h Not Found PHP Compilation

Issue

While compiling PHP from source on CentOS server, we get the error below:

checking whether to enable truetype string function in GD... yes
checking whether to enable JIS-mapped Japanese font support in GD... no
If configure fails try --with-webp-dir=<DIR>
configure: error: png.h not found.

The root of the problem is we’ve enabled this option –with-png-dir.

./configure --prefix=/usr/local/php7 \
    --with-config-file-path=/usr/local/php7/etc \
    --with-config-file-scan-dir=/usr/local/php7/etc/conf.d \
    --enable-bcmath \
    ...
    --with-freetype-dir \
    --with-png-dir

Solution

In this, we have to install the dependencies packages as follows:

sudo yum -y install libpng*
# yum list installed | grep libpng
libpng.x86_64                        2:1.5.13-8.el7                 @anaconda
libpng-devel.x86_64                  2:1.5.13-8.el7                 @base
libpng-static.x86_64                 2:1.5.13-8.el7                 @base
libpng12.x86_64                      1.2.50-10.el7                  @base
libpng12-devel.x86_64                1.2.50-10.el7                  @base

And then try to re-compile PHP from source and it should be able to compile this time.

Leave a Comment

Required fields are marked *