I have a program that accesses /dev/i2c-1. When run as root it works fine. Now I must be able to run this by using a PHP script on an Apache server. The program starts and runs OK, but user www-data cannot access i2c-1. Permission Denied! As suggested, I have added www-data to the i2c group, "adduser www-data i2c", but that did not help. I am using command line Debian Linux on a single board embedded device. How can I do this while keeping at least minimal security?
gI2c1File = open("/dev/i2c-1", O_RDWR);
if (gI2c1File < 0) {
file_logError("Error opening i2c-1 interface", strerror(errno));
return 0;
}
Just adding the apache user to the group is not enough; you must also confirm that the group permission on the '/dev/i2c-1' directory allow for reading and writing (or whatever task you want to perform on it.)
As root, you should perform the following command:
chmod g+rw /dev/i2c-1
This command will change the permission of this specified directory to allow for reading and writing to it by users in its group.