PHP exec mocp command

I want to play music through PHP on my raspberry Pi using Mocp (music on the console). This team

mocp -S

works fine in the console (it starts the mocp server), but in the PHP exec function it doesn't work:

<?php
    $ret = exec("mocp -S", $out, $err);
    print_r($ret);
    print_r($out);
    print_r($err);
?>

It just returns:

Array ( ) 2

According to this list return_var code 2 means

Incorrect use of embedded shells (as per Bash documentation)

But what exactly does this mean? The command mocp --helpworks both in the console and in PHP exec. How to run mocp with each parameter in PHP?

EDIT:
I just logged in as "www-data" (Apache user) and tried to execute mocp commands. I received this return:

FATAL_ERROR: unable to create directory /var/www/.moc

.moc Pi www-data ( "pi" ):

sudo cp /home/pi/.moc/ /var/www/.moc

script :

... Array ([0] = > ... [1] = > ...) 2

. www-data mocp -S

FATAL_ERROR: ()

2:
permsions /var/www/.moc. mocp -S,

...
...
ALSA...
ALSA lib confmisc.c: 768: (parse_card) '0'
ALSA lib conf.c: 4241: (_ snd_config_evaluate) snd_func_card_driver : Datei oder Verzeichnis nicht gefunden
ALSA lib confmisc.c: 392: (snd_func_concat) ,
ALSA lib conf.c: 4241: (_ snd_config_evaluate) snd_func_concat : Datei oder Verzeichnis nicht gefunden
ALSA lib confmisc.c: 1251: (snd_func_refer)
ALSA lib conf.c: 4241: (_ snd_config_evaluate) snd_func_refer : Datei oder Verzeichnis nicht gefunden
ALSA lib conf.c: 4720: (snd_config_expand) : Datei oder Verzeichnis nicht gefunden
ALSA lib pcm.c: 2217: (snd_pcm_open_noupdate) PCM
OSS...
FATAL_ERROR: !
FATAL_ERROR: !

+4
2

, www-data . , :

sudo usermod -a -G audio www-data
+2

:
raspbian :
sudo raspi-config ->Expand Filesystem ->Finish, reboot sudo apt-get update sudo apt-get upgrade sudo apt-get install apache2 php5 libapache2-mod-php5 sudo groupadd www-data sudo usermod -g www-data www-data sudo apt-get install moc sudo usermod -a -G audio www-data mocp -S sudo cp -R /home/pi/.moc /var/www/.moc sudo chown www-data /var/www/.moc/ sudo chmod -R a+rwxst .moc/
"www-data" mocp.

+1

Source: https://habr.com/ru/post/1599760/


All Articles