Installing FFmpeg on Laravel Cloud
Laravel Cloud is out, and I’ve already been using it for a few projects. Recently, I ran into a limitation: Laravel Cloud doesn’t allow installing persistent dependencies like FFmpeg. While they might offer this feature in the future, for now, we need to get creative.
Using Build Commands to Install FFmpeg
Laravel Cloud provides a Build Commands feature that lets you execute shell scripts during the build process. We’ll leverage this to install FFmpeg every time the app is deployed.
Initial Build Commands
By default, your build commands should look something like this:
_10composer install --no-dev_10_10# npm ci --audit false_10# npm run build
Now, let’s modify these steps to install FFmpeg.
Installing FFmpeg
We’ll download and install FFmpeg into the project’s home directory ($HOME/bin) so that it’s available during runtime.
_26# Install & Setup FFmpeg_26_26# Create a `bin` directory for custom binaries_26mkdir -p $HOME/bin_26cd $HOME/bin_26_26# Download the FFmpeg binaries_26curl -L -o ffmpeg.tar.xz https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-arm64-static.tar.xz_26_26# Extract the archive_26tar -xf ffmpeg.tar.xz_26_26# Rename the extracted directory_26mv ffmpeg-*-static ffmpeg_26_26# Grant execution permissions_26chmod +x $HOME/bin/ffmpeg/ffmpeg_26_26# Move back to the project root_26cd $HOME/html_26_26# Composer installation_26composer install --no-dev_26_26# npm ci --audit false_26# npm run build
Using the Correct Binaries
Now that FFmpeg is installed, you can use it in your Laravel application. If you’re using the php-ffmpeg/php-ffmpeg package, configure it like this:
_10$ffmpeg = FFMpeg\FFMpeg::create([_10 'ffmpeg.binaries' => '/var/www/bin/ffmpeg/ffmpeg',_10 'ffprobe.binaries' => '/var/www/bin/ffmpeg/ffprobe',_10]);
Refactoring the Installation Script
While adding the installation steps directly into your build commands works, it’s cleaner and more maintainable to move them into a dedicated script.
Creating a Deployment Script
Let’s create a file at ./deploy/ffmpeg.sh to handle the installation.
Updating Build Commands
Now, update your Laravel Cloud Build Commands to use the script:
_10# Install & Setup FFmpeg_10./deploy/ffmpeg.sh_10_10# Composer installation_10composer install --no-dev_10_10# npm ci --audit false_10# npm run build
Deploying & Verifying
Push your code and trigger a new deployment. If everything works correctly, your build logs should contain something like this:
_1000:00:48 Running build commands ————————————————————— Finished_10 Downloading FFmpeg..._10 Extracting FFmpeg..._10 FFmpeg installation completed successfully!_10 Setting up Composer..._10 ... Composer logs ...
And that’s it! You now have FFmpeg installed and running on Laravel Cloud. 🎉