Picture of Brian Love wearing black against a dark wall in Portland, OR.

Brian Love

PNG Support for PHP on OS X Yosemite

I recently upgraded to OS X Yosemite and ran into a small issue when attempting to create an image resource from a string. Here is what I am attempting to do:

The issue is that after upgrading to OS X Yosemite the PHP build that ships with OS X does not have PNG support enabled. It’s honestly a bit surprising that this was excluded from the build. Here is the error message that I received

Warning (2): imagecreatefromstring(): No PNG support in this PHP build

Install Homebrew

If you already have homebrew installed then you can skip this step. If not, it’s pretty quick. Homebrew enables us to easily install packages on OS X, including PHP.

First, you need to install Xcode (it’s free) from the App Store. Then, we need to install the command line tools.

$ xcode-select --install

Next, install the Homebrew package manager application.

$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Update Homebrew

If you just installed homebrew then you can skip this step, however, I still recommend that you run the first command to ensure your homebrew setup is configured correctly and that you do not get an errors.

Run the following command to validate your homebrew installation.

$ brew doctor

Run the following command to update your homebrew installation.

$ brew update

Tap Homebrew-PHP

Ok, now that we have homebrew installed and updated let’s start to upgrade our installation of PHP to the latest version with support for PNG images.

The first step is to tap the dependencies for Homebrew-PHP.

$ brew tap homebrew/dupes
$ brew tap homebrew/versions
$ brew tap homebrew/homebrew-php

Install PHP

Now we are ready to install PHP. I am going to install the latest stable build of PHP 5.6.

$ brew install php56

I ran into an error, which may be due to the version of some dependencies on my machine. If you do not get this error, you can skip down to the next sections on configuring Apache.

The error that I received was:

configure: error: GD build test failed. Please check the config.log for details.

I was able to correct this by running the following commands to remove and reinstall dependencies.

$ brew rm freetype jpeg libpng gd
$ brew install freetype jpeg libpng gd

After the successful installation of PHP you will see the following message.

==> Caveats To enable PHP in Apache add the following to httpd.conf and restart Apache: LoadModule php5_module /usr/local/opt/php56/libexec/apache2/libphp5.so

The php.ini file can be found in: /usr/local/etc/php/5.6/php.ini

I did also notice that the link step did not complete successfully either. Again, this could be due to my configuration, but just to note this I did receive the follow error.

Error: The brew link step did not complete successfully The formula built, but is not symlinked into /usr/local

To resolve this I had to force the linking to the new version of PHP I just installed.

$ brew link --overwrite php56

Configure Apache

The final step is to enable the PHP module in our Apache configuration file.

$ cd /private/etc/apache2/
$ sudo nano httpd.conf

If you have an existing LoadModule php5_module ... then you will want to comment this out. Then, paste in the line that homebrew provided:

Update httpd.conf

The last step is to restart Apache. You should also check your php_info(); to ensure that PNG support is now enabled.

$ sudo apachectl restart

PNG support enabled

PNG support is now enabled.