I'm trying to build a small webapp in PHP that allows me to control my DSLR with my rpi2. I am using the gphoto2 program, which is a console program that talks with most ptp cameras and can take pictures and store them on the pc/rpi. The command is working when I run it from the shell as root, though I did run into issues while logged in as a normal user. So I went ahead and wrote a udev rule to give 0666 to the device and allow everyone to use it which solved the problem with the user shell.

Next I wrote the PHP app that just runs a script that calls the gphoto2 command, and saves a picture in the same folder. Running the PHP code though the terminal with php -f worked just fine, but when I made an HTTP request to run it through Apache, it would print an error in the log saying that it doesn't have permission to access the device, even though it's still in 0666 mode.

I don't really see what else could be the problem, since everything but Apache can access the device just fine. Also I'm not really comfortable with running Apache as root and I know it's incredibly unsafe.

1 Answer 1


OK, I'm stupid, but I did not expect this. Pretty much just after posting the question I noticed that the php file does not have write permission for apache.

The Apache server DocumentRoot is a root:http owned folder and all files should be 664, but that one wasn't for whatever reason. So all php files that need usb device access (and possbibly for some other permissions as well) need to have the w permission enabled.

  • 2
    I find it hard to believe that giving write permissions to a PHP file would achieve anything. Jan 23, 2017 at 10:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.