Web Control of Raspberry Pi GPIO (UPDATED)

Step 6: Usage

To start the GPIO programs, do the following:

Start an SSH session with your Raspberry Pi, and login as root, then type in:
./ and hit Return / Enter.

It will ask you to input a wait time, this will depend upon your application needs, but the shorter the wait time, the more resources the script will use. (I generally use 5).

Now login to the web control interface, (http://HOSTNAME/control.php), login and enjoy.
Remove these adsRemove these ads by Signing Up
tmcisaac6 months ago
Quick query, just picked up a Raspberry Pi, got this setup and I was wondering. Can the other pins on the GPIO be addressed to add more buttons? (minus the DNC pins of course)
Rather n00b question, I know.
maco17177 months ago
Hi, Great tutorial! at last something that work for me. was trying with webGPIO for ages to then realize that the new version dont support to run from apache anymore so can use on my solution.

anyway was wondering what that sleep time? and it takes around 2s for the led to change state when i do trough web is this a normal delay time? would it be quicked with another solutions?

drcurzon (author)  maco17177 months ago
Hi there,
Glad you got it working. :)
the sleep time is the time before it updates each of the variables - the smaller the number, then more CPU + RAM usage, etc...
The delay is unfortunately due to the way the script works - there are other solutions - I believe you can call scripts directly from Python.
Many thanks, Dan.
maco1717 drcurzon7 months ago
yeah that's what i was trying, well first i tried php exec() with a bash script but would execute i guess because of permissions i was going to try python but i read that the script also need to be executed by admin so didnt try... is there any way around this?
the bash script was very basic, basically

# Set up GPIO 4 and set to output
echo "4" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio4/direction

# Write output
echo "1" > /sys/class/gpio/gpio4/value

and "0" to turn off...

all this in a .sh that was called from a button



also tried implementing a read status off led

exec('sudo cat /sys/class/gpio/gpio4/value',$outputArray);

but as is said no luck...

should i try with python?

exec(sudo python

maco1717 maco17177 months ago
i changed the visudo file to allow www-data apache user to edit files this allowed me to run
exec('sudo cat /sys/class/gpio/gpio4/value',$outputArray);

but the buttons are not working...
maco1717 maco17177 months ago
at last got it working.
my problem wasnt permission was not good web programing...

the page is like this now...

exec('cat /sys/class/gpio/gpio4/value',$outputArray);

if ($_GET['on']) {
# This code will run if ?run=true is set.
if ($_GET['off']) {



incredibly responsive
drcurzon (author)  maco17177 months ago
Hi there,
Nice to see you got it working :)
To make mine start up automatically, I put this line just before the "exit 0" in the /etc/rc.local file,

sleep 30
/var/www/ > /dev/null

Also, I added a line at the very beginning of the


I hope this helps.
jduffas1 year ago

I discovered a bug :
with safari on mac, if I use port 8000, I can't login any more...
il I delete the line : session_regenerate_id
frome the control.php script, It works ok...
is it a problem to remove that line ?

thank you.
drcurzon (author)  jduffas1 year ago
Hi there.
There's no real issue with removing that line, all it does is help towards the security of the login script, but shouldn't affect the system in any way.
Thanks, Dan.
pd5dj1 year ago
Hi all, i have tried to let it auto start during boot.
Uffortunally it boots, but then hangs in a loop of errors. after entering the wait time.
Cant find MySQL database etc bla bla...this because it is started to early.
I cant seem to kill the loop so it can continue to boot further..

Any ideas? btw im a real noob in linux...
drcurzon (author)  pd5dj1 year ago
Hi there,
As a work around, you could perhaps add a delay to the start of the script.
i.e. a For loop that goes for 30 seconds before allowing the rest of the script to run.

Many thanks, Dan.
First of all: great tutorial. Works perfect (just have to add "i" in "service" somewhere, but figured that out ;-)

1) how do I get the script to run at reboot?
2) when I reboot and run it manually, it sets all pins "high" - and updates the database. How can this be solved?
drcurzon (author)  frankdyring1 year ago
Hi there.
2. (Easiest to start with) I believe it is in the architecture of the Raspberry pi to set all pins high on boot up, however I may be incorrect.
I don't know of any way of changing this (but would be very interested if you found one).

1. I'll post a reply to your comment tomorrow, although I believe it to be a simple thing. Just a bit late here :)

Many thanks, Dan.
slopez211 year ago
How i cant execute the script always on de reboot as root?

Get More Out of Instructables

Already have an Account?


PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!