Awesome Open Source
Awesome Open Source

PHP7 Mapnik

PHP7 Mapnik


This project is an extension for PHP 7 that enables geospatial rendering with Mapnik. Create tile generation scripts, dynamic tile services, or static maps with Mapnik XML and PHP.

Build Status


  • PHP >= 7.0
    • Available through brew intall php on MacOS with Homebrew.
    • Available through sudo apt-get install php-dev php-gd on Ubuntu 16.04 Xenial.
  • Mapnik 3.0.x
    • Available through brew install mapnik on MacOS with Homebrew.
    • Available through sudo apt-get install libmapnik-dev on Ubuntu 16.04 Xenial.


git clone && cd php7-mapnik
./configure --with-mapnik
make test
make install
echo "" > /etc/php.d/mapnik.ini


  • The PHP configuration directory may differ from above. Run php -i | grep "Scan this dir" to find your system's location.
  • The ICU library path may need to be exported before building on MacOS. export LDFLAGS="-L/usr/local/opt/icu4c/lib"

Tile Server Example

Run the example...


...then visit http://localhost:8000/



// Register datasource plugins
// Use `mapnik-config --input-plugins` to get input plugin directory

// Create map
$map = new \Mapnik\Map(640, 480);

// Register fonts
// Use `mapnik-config --fonts` to get Mapnik fonts directory

// Load Mapnik XML
$map->loadXmlFile('my_awesome_map.xml', false, $basePath);

// Situate map content within canvas

// Create image
$image = new \Mapnik\Image(640, 480);

// Render
$renderer = new \Mapnik\AggRenderer($map, $image);

// Save PNG image file

See the API Documentation for a complete list of available objects and methods.

Dev Container

The included Dockerfile builds an image with all the dependencies needed for extension development and testing, including testing for memory leaks.

docker build -t php7-mapnik-dev .
docker run -it --mount type=bind,source=$(pwd),target=/opt/php7-mapnik php7-mapnik-dev:latest

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
c-plus-plus (18,586
php (16,544
geospatial (136