The Simple Raspberry PI on demand PHP Webcam


In this post I will show you how easy it is to set up a simple PHP scripted webcam that returns an image from the Raspberry PI camera on demand.

I will assume you  have the Raspberry PI, Camera and Debian with a web server running with PHP. (There are many tutorials out there offering this basic setup!)

1. Create a simple PHP script to return the image from the camera every time it is called: (Create this as “embed.php” in your public www folder:

system('sudo raspistill -hf -w 512 -h 320 -o /var/www/imageembed.jpg -t 0');
$filename = "imageembed.jpg";
$handle = fopen($filename, "rb");
$contents = fread($handle, filesize($filename));
echo $contents;


2. Now we can use this very simple code to embed the image into our webpage:


<center><h3><u>Live Webcam</u></h3></center><br>
<img src="">


You can embed this code directly on the PI or on some remotely hosted webspace!

If you find your apache web service is unable to run the raspistill command you may need to modify the www-data apache user to allow it to run the command:

echo 'SUBSYSTEM=="vchiq",GROUP="video",MODE="0660"' > /etc/udev/rules.d/10-vchiq-permissions.rules
 usermod -a -G video www-data


3 thoughts on “The Simple Raspberry PI on demand PHP Webcam

  1. Thanks very much!
    I was running a script that took new pictures from my webcam, and included the pictures with the tag, but the picture still was the old one.

  2. echo ‘SUBSYSTEM==”vchiq”,GROUP=”video”,MODE=”0660″‘ > /etc/udev/rules.d/10-vchiq-permissions.rules

    return permission denied . and when i check in my directory, 10-vchiq-permissions.rules doesn’t exist.

    Any suggestion? Should i just create a blank file with that name?

Leave a Reply

Your email address will not be published. Required fields are marked *