2

I have started a small project just for my practice in home. I am using a raspberry pi with debian linux,installed apache webserver 2 on the board,i have no idea on webserver but some how managed to create html page with button on it and cgi script running with button click.Cgi script has html code which respond to button click. Displays hello world followed by command invokes shell script .sh.

shell script has following command RPI.a(my project in c lang which invokes gpio pin running excellent when executing .cgi script in command line.

1)Overall Html button click ->2)invokes cgi script(shell with html)->3)invokes shell(.sh)-> which invokes my application blinking led.

Running good when executing .cgi manually from command line.but when on button click from html it skips "$(sh script.sh) and executes next line.

Permissions all the files has read and execute for all files.

.cgi script

#!/bin/bash
 echo "Content-type: text/html"
 echo "" 
echo "<html><head><title>Bash as CGI" 
echo "</title></head><body>" 
echo "<h1>Hello world</h1>"
 "$(sh Home_auto.sh)" 
echo "skipps the program" 
echo "</body></html>"

My Home_auto.sh script

sudo RPI.a<<EOF
EOF

ADDED my application Dir to $PATH var.

I found out that it is not able to execute my application few times when not being a root user.Display's RPI.a command not found Please help me with invoking script.sh which will invoke my RPI.a application on button click.

user3232919
  • 83
  • 1
  • 6

2 Answers2

2

Enable the cgi module by running a2enmod

If you don't see the following files

ls /etc/apache2/mods-enabled/cgi*

/etc/apache2/mods-enabled/cgid.conf
/etc/apache2/mods-enabled/cgid.load

Then you need to enable the cgi module

sudo a2enmod cgi
sudo service apache2 restart
  • Thank you very much – user3232919 Mar 30 '17 at 18:48
  • If you are looking for the `LoadModule` syntax, it is something to the effect of: `LoadModule cgid_module modules/mod_cgid.so` or `LoadModule cgi_module modules/mod_cgi.so` http://httpd.apache.org/docs/current/howto/cgi.html – cole Sep 21 '18 at 14:52
1

Check if www-data is able to execute the script (permissions, paths):

sudo su www-data /your/script.sh
PiEnthusiast
  • 314
  • 1
  • 4
  • 19