SIGN IN / UP
    opened image

    In this article, I will describe how to quickly install the ffmpeg extension for any PHP version in 5 minutes.

    The ffmpeg extension is outdated, not compatible with many libraries, not supported for over 15 years, and in general there are other better alternatives.

    However, there are still many projects that were written a long time ago and still use this extension.

    Fortunately, the ffmpeg-php extension can be installed on php versions from 5.4 to 8.2 (currently the latest)

    Installation instructions for this extension are often outdated, confusing and usually no longer work, in order to make it easier and make it possible to quickly install this extension on any php version in a few minutes, you can download ffmpeg  in archive that can be downloaded via the link here in this article. So let's start.

     

     

    Example of ffmpeg-php installation for PHP 5.4 on Centos 7.

     

    Install dependencies:

    yum install -y yum-utils epel-release 
    
    yum install -y wget autoconf automake gcc gcc-c++ m4 libtool make pkgconfig zlib bzip2 fribidi freetype fontconfig gnutls gd-devel libass libdrm openjpeg
    
    yum install -y php-devel 

     

     

    Download the archive and upload to the the server to the root folder and unpack. Link for downloading the archive

    cd /root
    
    tar -xzf ffmpeg-php.tar.gz
    
    rm ffmpeg-php.tar.gz

     

     

    Run next commands to copy the ffmpeg utility files from the archive and make ffmpeg available to the system:

    Attention! If ffmpeg is already installed on your system, copying the following files may lead to a conflict. If it is a VPS server, i recommend making a snapshot of the system, just in case. All actions you perform at your own risk!

    mv ffmpeg-php/centos7/ffmpeg /usr/local/
    
    echo 'export PATH="/usr/local/ffmpeg/bin:$PATH"' >> ~/.bashrc
    
    export PATH="/usr/local/ffmpeg/bin:$PATH"

     

     

    Next, install the PHP extension itself.

    If we need to install on PHP version 7.0 and higher, go to the php78 folder:

    cd /root/ffmpeg-php/php78/

    For PHP version 5.4-5.6, go to the php5 folder:

    cd /root/ffmpeg-php/php5/

     

    Let's build:

    /usr/bin/phpize
    
    CPPFLAGS="-I/usr/include/php/ext/gd -I/usr/local/ffmpeg/include" ./configure --enable-shared --prefix=/usr --with-php-config=/usr/bin/php-config --with-ffmpeg="/usr/local/ffmpeg"
    
    make && make install

     

     

    Now we need to connect the extension to our PHP. I have PHP running as an Apache module, so I need to restart the Apache service as well.

    echo 'extension=ffmpeg.so' > /etc/php.d/ffmpeg.ini
    
    systemctl restart httpd

     

     

    Done, now in phpinfo we should see that ffmpeg extension has been installed:

     

     

    Example of ffmpeg-php installation for PHP 8.2 on Ubuntu 20.04.

     

    Install dependencies:

    apt install -y wget autoconf automake build-essential m4 libtool make pkg-config zlib1g bzip2 libfribidi-bin libfribidi0 libfreetype6 fontconfig libgnutls30 
    
    apt install -y libgd-dev libass9 libdrm-common libdrm2 libopenjp2-7 libvdpau1 libxcb1 libxcb-shm0 libxcb-xfixes0 libxcb-shape0
    
    apt install -y php8.2-dev 

     

     

    Download the archive to the root folder and unpack. Link for downloading the archive

    cd /root
    
    tar -xzf ffmpeg-php.tar.gz
    
    rm ffmpeg-php.tar.gz
    

     

     

    Copy the files from the archive and make ffmpeg available to the system:

    Attention! If ffmpeg is already installed on your system, copying the following files may lead to a conflict. If it is a VPS server, i recommend making a snapshot of the system, just in case. All actions you perform at your own risk!

    mv ffmpeg-php/ubuntu20/ffmpeg /usr/local/
    
    echo 'export PATH="/usr/local/ffmpeg/bin:$PATH"' >> ~/.bashrc
    
    export PATH="/usr/local/ffmpeg/bin:$PATH"

     

     

    Next, install the PHP extension itself.

     For PHP version 5.4-5.6, go to the php5 folder:

    cd /root/ffmpeg-php/php5/

    For our example on PHP 8.2, go to the php78 folder:

    cd /root/ffmpeg-php/php78/

     

    Building the extension:

    Here the path /usr/include/php/20220829/ext/gd is different for each version of PHP, you will need to change it in 2 lines to the path you have in your system.

    /usr/bin/phpize8.2
    
    ln -s /usr/local/ffmpeg/lib/libcdio.so.16 /usr/lib/libcdio.so.16
    
    ln -s /usr/include /usr/include/php/20220829/ext/gd/libgd
    
    CPPFLAGS="-I/usr/include/php/20220829/ext/gd -I/usr/local/ffmpeg/include" ./configure --enable-shared --prefix=/usr --with-php-config=/usr/bin/php-config8.2 --with-ffmpeg="/usr/local/ffmpeg"
    
    make && make install
    

     

     

    Now we need to connect the extension to our PHP. I have PHP running in Apache + FastCGI mode in the Hestia panel, so I also need to restart the Apache and PHP-FPM services:

    echo 'extension=ffmpeg.so' > /etc/php/8.2/mods-available/ffmpeg.ini
    
    ln -s /etc/php/8.2/mods-available/ffmpeg.ini /etc/php/8.2/fpm/conf.d/20-ffmpeg.ini
    
    ln -s /etc/php/8.2/mods-available/ffmpeg.ini /etc/php/8.2/cli/conf.d/20-ffmpeg.ini
    
    systemctl restart apache2
    
    systemctl restart php8.2-fpm
    

     

    Done. The ffmpeg extension for PHP is installed.