Getting started with PHP Cairo graphics extension on XP

Posted on November 6, 2010


The Cairo graphics library ( is a widely used solution for rendering graphics to different devices – bitmaps, pdf, svg etc. It’s used by Mozilla, Inkscape, Gimp etc. Some time ago, I realized that Cairo is available as a native php extension: Great!

To get it running on XP, I did the following:

  1. Download fresh php binaries ( I choose the 5.2.14 zip package.
  2. Unzip the downloaded php zip.
  3. Download and unzip the the, conatining the cairo wrapper extension (php_cairo.dll). It can be found using the PHP 5.2 link available here: UPDATE: (Thank you, Jaffer Haider for pointing out this url!)
  4. Copying the php_cairo.dll from the downloaded cairo zip to the ext folder located insid the php directory.
  5. Editing the php.ini-recommended  filename (found in the php directory) to php.ini.
  6. Adding the line

    to the Windows Extensions part of php.ini (around line 664).

  7. This should be it!

Now, it should be possible to run php from the command line with cairo commands.
For example, create a file named “test_cairo.php” with the following content and put it in the php directory:

// test_cairo.php
$s = new CairoImageSurface(CairoFormat::ARGB32, 400, 400);
$c = new CairoContext($s);
$c->setSourceRGB(1, 0, 0);
$c->arc(200, 200, 100, 0, 2 * M_PI);
$c->setSourceRGB(0, 0, 0.6);
$c->rectangle(0, 160, 400, 75);

$s->writeToPng(dirname(__FILE__)  . '/test.png');

Now, run open a command line window in the php directory and run the testfile like this:

>php thest_cairo.php

This should produce a test.png looking like this:

The example is taken from Micahel Macleans ( talk on Graphics with Cairo – excellent read! Michael is one of the lead developers on the php cairo wrapper. Thank you, Michael!


If you want to use the cairo extension with PHP 5.2,  Eclipse PDT and Zend debugging client (, make sure to download the Non Thread Safe (PHP 5.2 NTS) from


Check out for php samples!


Posted in: PHP, Uncategorized