I was able to control one arm of an OWI-535 (Maplin) Robot Arm using GPIO pins and python programming (via L293 driver) , so I tried to do the same using a web page created in PHP.

Created buttons for forward and reverse motions and tried to call the python program but it does work.

The web page is being displayed and when I press the button, the strings 'test1 and test2' corresponding to the button press is being displayed. (using echo function in php)

I'm using LIGHTTPD web server. Here is the code.

exec('sudo python /var/www/ArmForward.py');
echo "test1";
exec('sudo python /var/www/ArmBackward.py ');

if(!(isset($_POST['ForwardMotion'])) & !isset($_POST['BackwardMotion']))

<form id=\"form1\" name=\"form1\" method=\"post\" action=\"Roboarmdemo.php\">
<table width=\"333\" height=\"124\" border=\"1\">
<td width=\"155\" height=\"30\"> UPWARD</td>
<td width=\"162\">DOWNWARD</td>
<td><input type=\"submit\" name=\"ForwardMotion\" value=\"Forward\" /></td>
<td><input type=\"submit\" name=\"BackwardMotion\" value=\"Backward\" /></td>



  • Hello. Did you bypass the PCB that came with that robot? I also got one but I cannot figure out how to send USB data to it? How did you connect it up. Sorry for no answer I am just interested in how you wired everything up cause I got the USB version of the robot.
    – Piotr Kula
    Nov 5, 2013 at 15:20
  • 1
    Related to your question I would suggest you rather use Node.JS instead. Why? node.js can execute the python directly at user level without PHP wrappers and all that junk in between. Node.JS is FAST and lightweight! You will not need PHP at all. Just use HTML markup with jQuery and AJAX calls to node.js. That means you get rid of bulky PHP calls. Code is separated, easier to understand and more secure. I would also suggest using nginx to host the pages as its blazingly fast and designed for embedded devices (although Lighttpd is not bad- At least you are not using Apache!)
    – Piotr Kula
    Nov 5, 2013 at 15:25
  • Why don't you just use python with the server directly and skip the PHP?
    – goldilocks
    Nov 5, 2013 at 15:38
  • 1
    @ppumkin...The robotic arm that I have is an old OWI-535 non usb type. I controlled it using the RPi GPIO pins via an L293 driver board. For usb type, a complete tutorial with coding is available in MAGPI magazine 2013 July edition.(Issue 14). I am new to PHP and python programming and I'm learning it, and regarding Node.js.....I have no idea about those things. I started with PHP and python, so I thought of completing with it. If you know how to execute python within php, it will be more helpful. Thank you
    – Ron Thomas
    Nov 6, 2013 at 8:07
  • @goldilocks...I don't know about writing python script for web page and I found PHP little more helpful as many knows about it
    – Ron Thomas
    Nov 6, 2013 at 8:10

3 Answers 3


Edit your /etc/sudoers

sudo nano /etc/sudoers


  • @s3bi.....Tried it but still didnt work.....No idea whats happening.
    – Ron Thomas
    Nov 7, 2013 at 17:21
  • is www-data in the same group as pi ? I had the same problem with a sh script and solved it by using this <?php exec("sudo /bin/sh /var/www/script.sh"); ?>
    – s3bi
    Nov 7, 2013 at 17:41
  • @s3bi..what do you mean by ' www-data in the same group as pi'? In the sudoers file, I have both pi and now www-data users.
    – Ron Thomas
    Nov 9, 2013 at 13:08
  • @s3bi....I wrote a simple python program to print my name and address and instead of using 'exec' command I used 'passthru' and I got the the three lines on the browser printed when I clicked the button. Code : passthru ('python /var/www/Simple.py) This is about exec and passthru---"exec() runs the program then sends back the last line outputted from that program as its return value. The passthru() function, on the other hand, runs the program specified and prints out all the output that program generates"
    – Ron Thomas
    Nov 9, 2013 at 13:13
  • @s3bi...Now its working perfectly, I made a mistake while giving "www-data ALL=(ALL) NOPASSWD: ALL" in /etc/sudoers, thats why it didn't work. Thanks a lot for the valuable inputs
    – Ron Thomas
    Mar 15, 2014 at 5:40

Alternatively, without making www-data a sudoer, you can look into some gpiod software that allow you to drive GPIO pins through a socket, without root privileges.


It is because lighttpd is being run from it's own user which is NOT:

  1. in the sudoers group
  2. listed as a sudoer with no password authentication for all commands

So basically the sudo command is being executed but it returns a warning about how the lighttpd user is not in the sudoers file/sudo group and this incident will be reported.

Two possible solutions would include:

  1. Adding lighttpd user(it's www-data or www, don't recall exactly) to the sudoers file and add the corresponding entry to execute python(or all commands) without using password authentication

  2. Run lighttpd as root user and omit sudo

The later solution is quick and dirty, but this is rPi. It's an embedded solution with probably no intention of leaving your desk, so basically do everything with root.

Oh and if you decide to make something production ready, please read online materials for securing embedded devices. Hope my answer was useful

  • Artis...Is this the command to add Lighttpd user to sudoers file %www-data ALL=(ALL) NOPASSWD: ALL I found it in some tutorial, not sure. How to run lighttpd as a root user??
    – Ron Thomas
    Nov 6, 2013 at 8:32
  • I am not sure that lighttpd will actually run it's operations as root. It is started by root but then it changes the user which it is being run under for security purposes. So pretty much you're left with sudo. If you open up /etc/sudoers there will be a line very similar to what you posted with the pi user, use that for reference. Just copy it and change from pi to www-data or whatever user lighttpd runs on your system
    – Artis
    Nov 6, 2013 at 9:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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