Apache的PHP调用ffmepg无需输入完整路径 [英] call ffmepg from apache php without full path

查看:197
本文介绍了Apache的PHP调用ffmepg无需输入完整路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个阿帕奇/ PHP不specifing在/ usr / local / bin目录/的ffmpeg的整体卫浴认识到FFmpeg的命令

从命令行调用的ffmpeg执行程序
通过网络从PHP调用的ffmpeg不执行程序
调用的/ usr / local / bin目录/从通过网络并执行程序PHP的ffmpeg

原因:
一个PHP脚本调用的YouTube-DL(编译程序),并在内部执行的ffmpeg

预先感谢您 -
尝试ffmpeg的路径:
    其中的ffmpeg
    在/ usr / local / bin目录/ ffmpeg的

 回声$ PATH
/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
#PHP code来进行测试:
$输出=了shell_exec('的/ usr / local / bin目录/ ffmpeg的2 - ;&放大器; 1');
回声壳EXEC在/ usr / local / bin目录/ ffmpeg的< pre> $输出< / pre>中;
#响应:
ffmpeg的版本2.5.3版权所有#(好)#Second PHP code来进行测试:
$输出=了shell_exec('ffmpeg的2 - ;&放大器; 1');
回声壳EXEC< pre> $输出< / pre>中;
#响应:
SH:ffmpeg的:没有找到命令#(坏)


解决方案

PHP使用默认的简介 反引号 / 了shell_exec 。它显然不包括的/ usr / local / bin目录 $ PATH 。为了解决这个问题,你可以明确的添加的/ usr / local / bin目录到您的默认路径:

 须藤回声$ PATH =的/ usr / local / bin目录:$ PATH'> /etc/profile.d/php_needed.sh

在现代系统 /etc/profile.d中文件夹的全部内容将包括在配置文件中。

I need a apache /php to recognize ffmpeg command without specifing the full bath of /usr/local/bin/ffmpeg

calling ffmpeg from command line executes the program calling ffmpeg from php via web does not execute the program calling /usr/local/bin/ffmpeg from php via web does execute the program

why: a php script calls youtube-dl (a compiled program) and executes ffmpeg internally

thank you in advance - tried ffmpeg path: which ffmpeg /usr/local/bin/ffmpeg

echo $PATH
/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin


#php code for testing:
$output = shell_exec('/usr/local/bin/ffmpeg 2>&1');
echo "shell exec /usr/local/bin/ffmpeg <pre>$output</pre>";
#Response:
ffmpeg version 2.5.3 Copyright #(good)

#Second php code for testing:
$output = shell_exec('ffmpeg 2>&1');
echo "shell exec <pre>$output</pre>";
#Response:
sh: ffmpeg: command not found #(bad)

解决方案

PHP uses default profile to execute commands with backticks/shell_exec. It apparently does not include /usr/local/bin in the $PATH. To fix the problem you might explicitly add /usr/local/bin to your default path:

sudo echo '$PATH=/usr/local/bin:$PATH' > /etc/profile.d/php_needed.sh

In modern systems the whole content of /etc/profile.d folder will be included in the profile.

这篇关于Apache的PHP调用ffmepg无需输入完整路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆