CentOS+FFmpeg+PHP完整安裝配置指南
環(huán)境準(zhǔn)備與系統(tǒng)更新
執(zhí)行系統(tǒng)更新確保軟件包最新:
yum update -y
yum install epel-release -y
rpm -Uvh http://rpms.remirepo.net/enterprise/remi-release-7.rpm
安裝編譯依賴包
安裝FFmpeg編譯所需基礎(chǔ)組件:
yum install -y gcc-c++ make automake autoconf libtool yasm
libpng-devel libjpeg-devel freetype-devel openssl-devel
nasm cmake mercurial wget git
源碼編譯FFmpeg
通過官方源碼編譯最新版FFmpeg:
wget https://ffmpeg.org/releases/ffmpeg-5.1.2.tar.gz
tar xzvf ffmpeg-5.1.2.tar.gz
cd ffmpeg-5.1.2
./configure --enable-shared --enable-libx264 --enable-gpl --enable-libmp3lame
make -j$(nproc)
make install
ldconfig
PHP環(huán)境配置
安裝PHP及必要擴展模塊:
yum install -y php php-cli php-common php-devel
sed -i 's/^disable_functions =.*/disable_functions =/g' /etc/php.ini
功能驗證測試
創(chuàng)建PHP測試腳本驗證FFmpeg集成:
<?php
$command = '/usr/local/bin/ffmpeg -version 2>&1';
exec($command, $output, $status);
echo $status === 0 ? "FFmpeg運行正常" : "配置異常";
print_r($output);
?>
常見問題處理
- 共享庫加載錯誤:執(zhí)行
ldconfig
刷新動態(tài)鏈接庫 - 權(quán)限問題:檢查SELinux狀態(tài)并適當(dāng)配置策略
- 路徑錯誤:使用
whereis ffmpeg
確認(rèn)可執(zhí)行文件位置