I'm building a system, using buildroot, that will have a webpage to control a raspberry's GPIO pins, using php. To do so, I'm writing (and reading) the kernel files located in /sys/class/gpio/.. the problem is that apache doesn't have permission to write or read in such directories and files. I can make it work by changing all directories permissions to:
chmod a+rx dir_name
But this has to be executed everytime the system is turned on since that the /sys/... permissions are reset to default when the system is turned off.
So I would like to know what's the easiest way to solve this problem? Not forgetting that at some point I might write into /sys/class/gpio/export a GPIO number creating a new directory (/sys/class/gpio/gpioN/ where N is the pin number) with new files wich permissions need to be changed aswell.
I'm not very skilled in this kind of stuff but the only way I can think of making it work is to run a script at boot that would export all GPIO pins (write in /sys/class/gpio/export) and then change the permissions of all directories and files. The problem is that I have no clue how to do such scripts, besides that it needs to be in /etc/init.d directory. I've looked in some of the files in this directory but can't understand them, what language is it written?
EDIT 1
I found in a post that to find the apache user I can run the following command:
ps aux | egrep '(apache|httpd)'
Wich outputs the following:
135 root /usr/bin/httpd -k start
138 daemon /usr/bin/httpd -k start
139 daemon /usr/bin/httpd -k start
140 daemon /usr/bin/httpd -k start
1133 root egrep (apache|http)
sudo
config file. sudo is a program that lets you configure things so thatsudo command
, when run by an ordinary user, runscommand
as root. This question has more details; allowing writes to /sys by ordinary users is a common question. An init script would be easier, except that you said you'll need to chmod the files and directories at arbitrary times after booting. – Mark Plotnick Dec 28 '17 at 11:05udev
handles, but you might not have that); you'll need to run more chmod or chown commands. Hopefully someone familiar with your specific type of small system can offer a convenient way to do what you want. – Mark Plotnick Dec 28 '17 at 12:27ps -eo pid,fsuid,cmd|grep httpd
to see the uid the httpd processes are using to access files, and usechown
to change the owner of the files and directories to that. Then you can make the permissions on those files and directories as restrictive as you want - readable and writable by owner for files, rwx by owner for directories, and no access for anyone else. – Mark Plotnick Dec 28 '17 at 14:57