0
votes

I've set up a VPS server on Digitalocean. Installed Ubuntu 18.04, LAMP, etc. Finally, I installed ffmpeg. It is working fine from terminal but when I try to execute it through php it gives a weird "Permission denied" error:

Here is some information:

root@vl:/# whereis ffmpeg
ffmpeg: /usr/local/bin/ffmpeg
root@vl:/# whereis ffprobe
ffprobe: /usr/local/bin/ffprobe

root@vl:/# ffmpeg -version
ffmpeg version N-102461-g8649f5dca6 Copyright (c) 2000-2021 the FFmpeg developers built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04) configuration: --prefix=/usr/local/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/usr/local/ffmpeg_build/include --extra-ldflags=-L/usr/local/ffmpeg_build/lib --extra-libs='-lpthread -lm' --ld=g++ --bindir=/usr/local/bin --enable-gpl --enable-gnutls --enable-libaom --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libsvtav1 --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree libavutil 57. 0.100 / 57. 0.100 libavcodec 59. 1.100 / 59. 1.100 libavformat 59. 0.101 / 59. 0.101 libavdevice 59. 0.100 / 59. 0.100 libavfilter 8. 0.101 / 8. 0.101 libswscale 6. 0.100 / 6. 0.100 libswresample 4. 0.100 / 4. 0.100 libpostproc 56. 0.100 / 56. 0.100

My php file:

echo shell_exec("ffmpeg -i mj.gif -profile:v baseline -pix_fmt yuv420p -vf scale=600:-2 output.mp4 2>&1")
?>

The ERROR!:
ffmpeg version N-102461-g8649f5dca6 Copyright (c) 2000-2021 the FFmpeg developers built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04) configuration: --prefix=/usr/local/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/usr/local/ffmpeg_build/include --extra-ldflags=-L/usr/local/ffmpeg_build/lib --extra-libs='-lpthread -lm' --ld=g++ --bindir=/usr/local/bin --enable-gpl --enable-gnutls --enable-libaom --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libsvtav1 --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree libavutil 57. 0.100 / 57. 0.100 libavcodec 59. 1.100 / 59. 1.100 libavformat 59. 0.101 / 59. 0.101 libavdevice 59. 0.100 / 59. 0.100 libavfilter 8. 0.101 / 8. 0.101 libswscale 6. 0.100 / 6. 0.100 libswresample 4. 0.100 / 4. 0.100 libpostproc 56. 0.100 / 56. 0.100 Input #0, gif, from 'mj.gif': Duration: 00:00:01.60, start: 0.000000, bitrate: 22863 kb/s Stream #0:0: Video: gif, bgra, 1400x1050, 10 fps, 10 tbr, 100 tbn output.mp4: Permission denied

From the past 24 hours I've tried installing ffmpeg in different ways (compiling & apt install), I've also tried changing the permission but still I'm stuck with this error.
Any help would be highly appreciated!
Thanks

2
How did you change permissions? In console will be a rol and Apache/PHP other.Fran Cerezo
I tried to change permissions of /usr/local/bin (chmod 755 /usr/local/bin and chmod 777 /usr/local/bin) then I tried to move user "www-data" to group "video" by using this "usermod -a -G video www-data".. nothing worked so far!DJ Danny

2 Answers

0
votes

php shell stuff runs from a different user as root and you used root to execute it in the terminal. You would need to give the www-data user permission to run the file. probably because the file ffmpeg is trying to access (mj.gif) doesn't have permissions set for everyone to read the file. Try running chmod 755 mj.gif in the directory the gif is in.

0
votes

Instead

echo shell_exec("ffmpeg -i mj.gif -profile:v baseline -pix_fmt yuv420p -vf scale=600:-2 output.mp4 2>&1")

try something like

echo shell_exec("ffmpeg -i mj.gif -profile:v baseline -pix_fmt yuv420p -vf scale=600:-2 /var/www/your_app/output.mp4 2>&1")

If it fails try chmod 777 /var/www/your_app