Lost in technical reverie

Lost in technical reverie
Helping solve technical issues, digital musings, and the odd rant.

Tuesday, January 21, 2014

Recompile PHP with bundled GD library

When a security issue or bug is discovered in a library, the issue can be fixed easily. The library package is rebuilt, redeployed, and all the applications that use it are protected from the issue. When bundling is allowed, the distro needs to find all the packages the library was bundled with. All of those packages need to be fixed. You shouldn't assume an upstream maintainer is plugging security issues. There are several other technical reasons that I won't cover here, but you get the idea. 

How does this affect your web server?

So there's no bundled libraries in Debian or Ubuntu. Debian policy does not build packages with embedded copies of 3rd party code. Due to upstream syncing issues, package maintainer animosity, and Debian policy, GD sources used for libgd in Debian are missing certain functions.

If you happily installed PHP with GD using apt-get install php5-gd you should be aware the following functions are missing
    function imageantialias
    function imagecolormatch
    function imageconvolution
    function imagecreatefromxbm
    function imagecreatefromxpm
    function imagefilter
    function imagelayereffect
    function imagerotate
    function imagexbm

Galleries, images, and photos will suddenly disappear from your web-pages. Errors logs will start to fill up with messages similar to this one:

PHP Fatal error:  Call to undefined function imageantialias()

How can I fix undefined function errors?

Recompile PHP. Don't fret, this is straight forward in Debian.

Install build tools required to compile source code
> apt-get install build-essential debhelper fakeroot

Obtain the PHP source code
> cd /usr/src
> sudo apt-get source php5

Install all dependencies required to build PHP5
> sudo apt-get build-dep php5

Build the package
> cd php5-x.x.x (replace 'x' correct version number)
> sudo dpkg-buildpackage -rfakeroot

This will take some time, treat yourself to a refreshment
When the .deb is compiled, traverse back a folder.
> cd ..

Install the required package*
> sudo dpkg -i php5-gd_5.x.x.x.deb

*Don't forget to restart apache.

Be a good administrator, hold that package

You've customized your current package and you don't want to overwrite it, no matter what. Holding a package informs the package manager to retain the current installed version. The next time you run apt-get update and apt-get upgrade you won't overwrite all of your hard work.

Using dpkg
> sudo echo php5-gd hold | dpkg --set-selections

Using apt
> sudo sudo apt-mark hold php5-gd

No comments:

Post a Comment