Firstly to get it working at all I needed to edit /etc/sudoers file using visudo. I gave www-data the same permissions as the default user pi by the following to the end of the file:
www-data ALL=(ALL) NOPASSWD: ALL
I also needed to change the permissions on the USB port in use for it all to work. Using the info from earlier in the thread to find the port I created the following script called usbperm
#!/bin/bash
#
dev=`gphoto2 --auto-detect | grep usb | cut -b 36-42 | sed 's/,/\//'`
sudo chmod 777 /dev/bus/usb/${dev}
exit 0
Changing the permissions to 777 maybe overkill but it works!
Then just a couple of weeks to get the web page working as I wanted and looking pretty (please notice the symbols matching the camera ones and rounded corners!)
I found using exec('gphoto2 --list-all-config',$output,$int); to get the camera config settings and then parsing it to find the individual settings was much faster than separate calls to get each one.
Changes then made using --set-config from popup windows for each setting.
Clicking on the look-a-like camera button takes a picture with
exec('gphoto2 --capture-image-and-download --keep --filename capt0000.jpg --force-overwrite --quiet');
For my Canon I also needed to insert every time a --set-config /main/settings/capturetarget=1 to force it to use the card and not the internal memory of the camera which it keeps defaulting to.
Clicking on Preview takes a quick preview (if the camera supports it) using
exec('gphoto2 --capture-image-and-download --filename capture_preview.jpg --force-overwrite --quiet')
Of course after each call to gphoto2 I need to do a usb reset with
exec('usbreset /dev/bus/usb/'.$dev);
usbreset and usbperm were added to /usr/bin/ with full permissions.