Simple Raspberry Pi Camera Photo Gallery Using PHP


There are a lot of Raspberry Pi camera projects out there that capture photos. Obviously. I’ve found a nice PHP script that lets you view these photos directly from the Pi via a web browser. The script is called “Single File PHP Gallery” and it’s free.

Single File PHP Gallery is a web gallery in one single PHP file created by Kenny Svalgaard. All you have to do is copy the script to any directory containing images to make a gallery. This makes it perfect for quickly adding some fantastic functionality to your Pi camera projects with a minimum of effort. Why spend days writing your own image presentation system when you can do it it 5 minutes?

Single File Gallery ScriptSub directories are treated as sub galleries and the script can generate thumbnails for images and directories automatically.

Single File PHP Gallery does not require any configuration or programming skills to use. You just drop the file into your photo directory and you are ready to go. The only requirements are that your Pi is running a web-server and your photos are in a directory visible to that server.

Single File Gallery ScriptDon’t worry. That’s easy to setup if you haven’t already and it will be explained below.

Features :

  • Free for private non commercial use
  • Uses no database
  • Automatically creates thumbnails
  • Displays EXIF information
  • Option to add watermarks
  • Supports JPG, JPEG, PNG and GIF
  • Unlimited numbers of sub galleries

Step 1 – Install Lighttpd Web Server

First you need an active web server running on your Pi. You can use any PHP enabled server but I use Lighttpd and instructions for setting this up can be found in my Install a Raspberry Pi Web Sever article. Make sure you get the test page working before continuing.

Once you’ve completed this step the /var/www directory will be able to serve PHP files. Let’s make a directory for some photos :

mkdir /var/www/photos

Step 2 – Install PHP GD Library

The script makes use of the PHP GD image processing library. To install this you can use the command :

sudo apt-get update
sudo apt-get -y install php5-gd

Step 3 – Add Single File PHP Gallery Script

Next we need to download the Single File PHP Gallery script and make sure it is placed in our photo directory. Let’s make sure we are in the home directory :

cd ~

and then grab the script from the project web site :


Now we need to extract the contents of this archive into the directory that will contain our photos or sub-directories containing photos :

unzip -d /var/www/photos

You should see the following output :

inflating: /var/www/photos/index.php
inflating: /var/www/photos/readme.txt

Step 4 – Add Some Photos

You can either use the Pi camera to save files to the /var/www/photos/ directory or you cheat and copy some photos in manually just to test your setup. I copied a set of existing photos into the directory using FTP so I could get some example screenshots.

Step 5 – View The Gallery

In order to test your gallery you need to know the IP address your Pi has on your network. To do this run this command :

sudo ip addr show

You will see a block of information similar to this :

 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
 inet scope host lo
 link/ether b1:11:ab:42:24:2c brd ff:ff:ff:ff:ff:ff
 inet brd scope global eth0

The IP address in this example is Take this IP address and enter it into the address bar of a web browser on another device. You should see the index.php page that is sitting in /var/www/.

Now enter the IP address but this time add /photos/ to the end :

If everything has worked you should see the photo gallery.

Single File Gallery Script

Clicking into a folder will show the photos within that folder :

Single File Gallery Script

Clicking an individual photo will show you a larger version :Single File Gallery Script

You can also turn on an information panel which will display technical information about the photo :

Single File Gallery Script

The thumbnails are generated the first time the page is loaded in a browser. How long it takes to generate will depend on the number of images in the directory and how big they are.

It’s possible to create your own thumbnails if you prefer. This and many other tweaks is explained in the readme.txt file which should have been extracted to the /var/www/photos/ directory.



  1. David ROBERTS on

    Step 3:
    unzip /var/www/photos

    results in
    pi@raspberrypi ~ $ unzip /var/www/photos
    caution: filename not matched: /var/www/photos

    Specifying the destination directory with -d works –
    pi@raspberrypi ~ $ unzip -d /var/www/photos
    inflating: /var/www/photos/index.php
    inflating: /var/www/photos/readme.txt

    [Thanks for the write-up, and for giving an example of a very clear writing style.]

    • Thanks David. I’ve corrected it now. I used the “-d” when I tested the technique but must have missed it in a cut-n-paste somewhere.

    • May be you did not install php5-gd, try to install it or reinstall it. The other issue may be that php has no right to write in the folder indicated in the script for the root of the gallery.

  2. Hi, any idea, why my Rasp II is very slow loading the full version of a pic (out of an 14MP DSLR) – no matter if cached or not. I am using Apache instead of lighthttpd.
    I want to use it in a photobooth for the wedding of my little sister. People should be able to download their phots on Smartphones, but i guess my Rasp ‘ll tilt if more than 5 people are browsing the gallery…

    • /var/www is the folder used by the webserver. The folder under that can be any folder(s) as long as the script is in there as well. ie /var/www/media/photos/

Leave A Reply