The location of the shellscript is important, and the path you're using are important. Even if alert.sh
is located at /var/www
, the current working directory can be different. Use echo getcwd();
to get the current working directory. With an absolute path, you would use:
shell_exec('/var/www/alert.sh');
The second possibility (most likely) is that the file mode (file permissions) is insufficient. The Apache webserver runs as user www-data
. If the alert.sh
is owned by you, has your group and has execute permissions for the owner only, the apache server cannot execute it. Possible permissions (practicing the least privilege rule) are:
- 755 - owner: you - group: you
- 750 - owner: you - group: www-data
- 644 or 640 - owner: you - group: you or www-data
The last option works only if you execute the script like shell_exec('/bin/sh alert.sh')
. The shell program /bin/sh
only needs to be able to read the script after which the data is executed.