I am trying to use PHP to play a sound ON SERVER SIDE once someone visits my webpage. It's running on Nginx/Php5 (raspberry pi).
This is how I'm trying to do it:
I have executed command:
sudo usermod -aG audio www-data
The php file:
<?php
$audio = shell_exec('sh play.sh');
echo $audio;
?>
But it results nothing.
Running 'id' command with the same method results:
uid=33(www-data) gid=33(www-data) groups=33(www-data),29(audio),44(video)
I don't know if its relevant but:
ls -lah /dev/snd
drwxr-xr-x 3 root root 160 Oct 26 17:22 .
drwxr-xr-x 15 root root 3.5K Oct 26 17:22 ..
drwxr-xr-x 2 root root 60 Oct 26 17:22 by-path
crw-rw----+ 1 root audio 116, 0 Oct 26 17:22 controlC0
crw-rw----+ 1 root audio 116, 16 Oct 26 17:22 pcmC0D0p
crw-rw----+ 1 root audio 116, 17 Oct 26 17:22 pcmC0D1p
crw-rw----+ 1 root audio 116, 1 Oct 26 17:22 seq
crw-rw----+ 1 root audio 116, 33 Oct 26 17:22 timer
Executing the following command plays the file properly:
sudo -u www-data play ding.mp3
But using the following one:
sudo -u www-data sh play.sh
Results:
Sorry, user www-data is not allowed to execute '/usr/bin/play /var/www/ding.mp3' as www-data on raspberrypi.
The script contains the following:
#!/bin/sh
sudo -u www-data /usr/bin/play '/var/www/ding.mp3'
Any other command in that script is executed properly. Anyone could give me some advice?