简体   繁体   English

PHP exec mocp命令

[英]PHP exec mocp command

I want to play music via PHP on my Raspberry Pi with Mocp (music on console). 我想在我的Raspberry Pi上使用Mocp(控制台上的音乐)通过PHP播放音乐。 This command 这个命令

mocp -S

works just fine in the console (it starts the server of mocp) but in PHP's exec function it doesn't work: 在控制台中工作正常(它启动mocp的服务器)但在PHP的exec函数中它不起作用:

<?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 根据这个列表 return_var代码2的意思

Misuse of shell builtins (according to Bash documentation) 滥用shell内置(根据Bash文档)

But what exactly does this mean? 但究竟是什么意思呢? The command mocp --help works in both console and PHP exec. 命令mocp --help在控制台和PHP exec中都有效。 How can I run mocp with every parameter in PHP? 如何在PHP中使用每个参数运行mocp?

EDIT: 编辑:
I just logged in as "www-data" (the apache user) and tried to run mocp commands. 我刚登录为“www-data”(apache用户)并尝试运行mocp命令。 I got this return: 我得到了这个回报:

FATAL_ERROR: Can't create directory /var/www/.moc FATAL_ERROR:无法创建目录/var/www/.moc

I copied the .moc folder of Pi to www-data (with user "pi"): 我将Pi的.moc文件夹复制到www-data (用户“pi”):

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

Now my script from above gives me: 现在我的上面的脚本给了我:

Running the server...Array ( [0] => Running the server... [1] => Running the server... ) 2 运行服务器...数组([0] =>运行服务器... [1] =>运行服务器...)2

But it still does not work. 但它仍然无效。 In the console of www-data mocp -S now gives me 在www-data的控制台中, mocp -S现在给了我

FATAL_ERROR: Can't bind() to the socket FATAL_ERROR:无法bind()到套接字

EDIT 2: 编辑2:
I changed the permsions on /var/www/.moc . 我改变了对permsions /var/www/.moc If I try mocp -S , I get this 如果我尝试mocp -S ,我会得到这个

Running the server... 运行服务器......
Trying JACK... 试着JACK ......
Trying ALSA... 尝试ALSA ......
ALSA lib confmisc.c:768:(parse_card) cannot find card '0' ALSA lib confmisc.c:768:(parse_card)找不到卡'0'
ALSA lib conf.c:4241:(_snd_config_evaluate) function snd_func_card_driver returned error: Datei oder Verzeichnis nicht gefunden 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) error evaluating strings ALSA lib confmisc.c:392:(snd_func_concat)错误评估字符串
ALSA lib conf.c:4241:(_snd_config_evaluate) function snd_func_concat returned error: Datei oder Verzeichnis nicht gefunden ALSA lib conf.c:4241:(_ snd_config_evaluate)函数snd_func_concat返回错误:Datei oder Verzeichnis nicht gefunden
ALSA lib confmisc.c:1251:(snd_func_refer) error evaluating name ALSA lib confmisc.c:1251:(snd_func_refer)错误评估名称
ALSA lib conf.c:4241:(_snd_config_evaluate) function snd_func_refer returned error: Datei oder Verzeichnis nicht gefunden ALSA lib conf.c:4241:(_ snd_config_evaluate)函数snd_func_refer返回错误:Datei oder Verzeichnis nicht gefunden
ALSA lib conf.c:4720:(snd_config_expand) Evaluate error: 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) Unknown PCM default ALSA lib pcm.c:2217:(snd_pcm_open_noupdate)未知的PCM默认值
Trying OSS... 尝试OSS ......
FATAL_ERROR: No valid sound driver! FATAL_ERROR:没有有效的声音驱动程序!
FATAL_ERROR: Server exited! FATAL_ERROR:服务器已退出!

Seems like www-data user doesn't have right access permissions to use your audio device. 好像www-data用户没有使用音频设备的权限。 I belive executing this should help: 我相信执行这应该有帮助:

sudo usermod -a -G audio www-data

My full solution of the problem: 我完全解决了这个问题:
I started with a new installation of raspbian and ran those comands: 我开始使用新的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/
At the end user "www-data" is able to run mocp. 最后,用户“www-data”能够运行mocp。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM