I try to execute a shell from a PHP using exec_shell() function, but it doesn't working.

I've tried chmod, chown and doesn't execute but on terminal yes. Sorry for this question but I really need a help. <3


Code: <?php echo "<pre>".shell_exec('mpg321 whisper.mp3 2>&1 1> /dev/null')."</pre>"; ?>


Version 0.3.2-1 (2012/03/25). Written and copyrights by Joe Drew,
now maintained by Nanakos Chrysostomos and others.
Uses code from various people. See 'README' for more!
tcgetattr(): Inappropriate ioctl for device
Title   : Whisper                        Artist : Samsung                       
Album   : Samsung                        Year    :                               
Comment :                                Genre : Alert Tone                    

Playing MPEG stream from whisper.mp3 ...
MPEG 1.0 layer III, 128 kbit/s, 44100 Hz joint-stereo
Home directory not accessible: Permission denied
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.front
ALSA lib confmisc.c:767:(parse_card) cannot find card '0'
ALSA lib conf.c:4568:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
ALSA lib conf.c:4568:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name
ALSA lib conf.c:4568:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5047:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM default
Can't find a suitable libao driver. (Is device in use?)
  • Give the full path to programs and files.
    – joan
    Jan 21, 2021 at 17:35
  • I did this: /usr/bin/mpg321 /var/www/html/whisper.mp3 2>&1 1> /dev/null but doesn't work :( Jan 21, 2021 at 18:19
  • ...and the error was?
    – joan
    Jan 21, 2021 at 18:30
  • The same, but with Directory: /var/www/html... the same... Jan 21, 2021 at 19:17

1 Answer 1


Alsa may be attempting to access the config file for the user (usually www-data) at ~/.asound. Make sure that the user has a home directory, and that it's accessible.

As root:

# mkdir ~www-data
# chown www-data.www-data ~www-data

Of course there are probably good reasons not to solve the problem this way specifically ... Usually it's a better idea to create a shell script that can run suid as a user that has a working configuration (assume user pi here).


if [[ $(id -u) -ne $(id -u pi) ]]; then echo "wrong user!"; exit 1; fi
/usr/bin/mpg321 /var/www/html/whisper.mp3 2>&1 >/dev/null

as user pi, set the suid bit which will force the shell to be run with the effective uid of the owner of the file (pi in this case).

chmod go+s /home/pi/whisper.sh

Now, in your PHP, execute the whisper.sh script instead:

<?php echo "<pre>".shell_exec('/home/pi/whisper.sh')."</pre>"; ?>

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.