PHP Classes


Recommend this page to a friend!
  Classes of Andrew Collington   iWire PHP Raspberry PI GPIO Class   Download  
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: iWire PHP Raspberry PI GPIO Class
Control a Raspberry PI board using GPIO
Author: By
Last change:
Date: 4 years ago
Size: 2,728 bytes


Class file image Download


A wrapper for wiringPi written in Zephir so that is can be compiled as an extension for PHP.

Flattr this git repo


This extension and the wiringPi library are intended to run on a RaspberryPi, so having a RaspberryPi is kind of a big requirement here! You also need to have Git installed, the wiringPi library, various build tools and the php development headers.

Installing Git

sudo apt-get update
sudo apt-get install git

Installing wiringPi

git clone git://
cd wiringPi

If all goes well you should be able to run the gpio utility:

gpio -v

Full instructions for installing wiringPi.

Installing zephir

sudo apt-get install gcc make re2c php5 php5-json php5-dev libpcre3-dev
git clone
cd zephir
./install -c

If all goes well you should be able to get the help info for zephir:

zephir help

Full instructions for installing zephir.

Building the extension

git clone
cd phpiwire
zephir build

That will build and install the extension. You'll then have to add the extension to your php.ini file. You may find that you have two php.ini files, one for cli and one for web, so remember to add the extension to both. You'll want to add the line:

Once this is done (and the web server restarted if you're adding the extension for web use and not just cli) you should be able to see the extension info when using the `phpinfo()` method or via the command line `php -i`.


Here's a very simple example of how to make an LED attached to pin 0 (using the wiringPi pin numbering scheme, BCM_GPIO pin 17) blink on and off.

Assuming the LED is attached as shown:



namespace Phpiwire;


echo "Raspberry Pi blink\n";

$pi = new Board();
$p = $pi->getPin(0)->mode(Pin::OUTPUT);

while (true) {

And to run it you'll need to be running as root:

sudo php blink.php


Releases of the extension are available at: