Category: Shell

A tiny blog for DevOPS related items

Always in for coffee and cookies

Recompile GD for PHP5.6

When using PHP5.6 with the GD module enabled, you can miss out on some GD function when PHP itself isn’t compiled with GD support enabled.
Errors like this may pop up in your php_error.log:

PHP Fatal error:  Call to undefined function imageantialias() in ...

If we test this via the command line, we can see that it’s true (why shouldn’t it be?):

$ php -r "var_dump(function_exists('imageantialias'));"
bool(false)

Recompiling PHP is a way to go, but could bring some unexpected issues if you don’t know what you’re doing.
Another option is to rebuild the GD module.

In order for this to work, i had to install some packages.
This might not be the case for you. The packages i needed to install before recompiling were:

Next, download your version of the PHP source and move to the GD extension directory.
For me, this was PHP 5.6.31

$ cd /tmp
$ wget http://cz2.php.net/get/php-5.6.31.tar.gz/from/this/mirror -O php-5.6.31.tar.gz
$ tar -xvf php-5.6.31.tar.gz
$ cd php-5.6.31/ext/gd

Prepare the extension:

$ phpize

Configure the extension:

$ ./configure --with-php-config=/usr/bin/php-config --with-freetype-dir=<YOUR_VALUE> --with-jpeg-dir=<YOUR_VALUE> --with-xpm-dir=<YOUR_VALUE> --with-vpx-dir=<YOUR_VALUE> --with-t1lib

You can find the required values by running this command:

$ php-config --configure-options

After the configuration is done, run make:

$ make

When make is done, you should get output similar like this:

----------------------------------------------------------------------
Libraries have been installed in:
   /tmp/php-5.6.31/ext/gd/modules

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
Installing shared extensions:     /usr/lib64/php/modules/
Installing header files:           /usr/include/php/

Copy the gd.so file from the modules dir, to the modules dir of your PHP installation.
You need to overwrite the gd.so file that already is present.
In this case that was /usr/lib64/php/modules/ as was told by the output above.

Restart Apache, and verify that the new GD module is working.
Check phpinfo(); to see if the module is there and check your error logs to see if PHP isn’t having trouble with your new GD extension.

If that’s all good, function_exists() should return true now.

$ php -r "var_dump(function_exists('imageantialias'));"
bool(true)