asd3344
Posts: 6
Joined: Fri Apr 11, 2014 11:55 pm

php run shell script

Sat Apr 12, 2014 12:10 am

hi


I have script like

Code: Select all

#!/bin/sh
#
echo 1 > /sys/devices/virtual/gpio/gpio4/value

name XX.sh

I want php file has a button when I press this button .. XX.sh run

I tried ( exec , shell_exec )

please help :(

User avatar
Richard-TX
Posts: 1549
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas

Re: php run shell script

Sat Apr 12, 2014 3:03 am

use full pathnames in your php script
chmod your script to something like 755
Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip

asd3344
Posts: 6
Joined: Fri Apr 11, 2014 11:55 pm

Re: php run shell script

Sat Apr 12, 2014 12:26 pm

Richard-TX wrote:use full pathnames in your php script
chmod your script to something like 755

thanks this what I write in php

Code: Select all


<?php

$output = shell_exec('sudo /var/www/XX.sh');
echo "<pre>".$output."</pre>";
?>

I tried every thing

User avatar
Richard-TX
Posts: 1549
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas

Re: php run shell script

Sun Apr 13, 2014 3:45 am

The problem is that you are calling sudo and should be calling /usr/bin/sudo.

EVERY command needs the full pathname
Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip

Return to “General programming discussion”