Make your own YouTube Downloader Mp3 Site
- Linux
- php >= 8.4.1 with the
pdo_sqliteextension (used by the default SQLite database) - Laravel 12
- Web server
- Composer
- yt-dlp, latest release (https://github.com/yt-dlp/yt-dlp)
- Deno, the JavaScript runtime yt-dlp needs for YouTube (https://deno.com/)
- ffmpeg (https://ffmpeg.org/)
Don't install yt-dlp with
apt. The distribution package is usually outdated, and YouTube breaks old versions quickly (errors likeHTTP Error 400: Precondition check failedorRequested format is not available).
Install ffmpeg, the SQLite PHP extension and the tools the installers below need:
sudo apt install -y ffmpeg curl unzip php8.4-sqlite3 # use the package for your PHP versionInstall the official yt-dlp binary in /usr/local/bin, so every user, including the web server
user (www-data), can find it. It is downloaded to a temporary file first, so a failed download
does not break an existing installation:
case "$(uname -m)" in aarch64|arm64) asset=yt-dlp_linux_aarch64 ;; *) asset=yt-dlp_linux ;; esac
curl -fL -o /tmp/yt-dlp "https://github.com/yt-dlp/yt-dlp/releases/latest/download/$asset" \
&& sudo install -m 0755 /tmp/yt-dlp /usr/local/bin/yt-dlp \
&& rm /tmp/yt-dlpIf you previously installed yt-dlp with apt, remove it:
sudo apt remove -y yt-dlpInstall Deno system-wide:
curl -fsSL -o /tmp/deno-install.sh https://deno.land/install.sh \
&& sudo DENO_INSTALL=/usr/local sh /tmp/deno-install.sh \
&& rm /tmp/deno-install.shCheck the installation:
yt-dlp --version
deno --version
ffmpeg -versionKeep yt-dlp up to date. When downloads stop working, updating it is usually the fix:
sudo yt-dlp -Ubrew install ffmpeg yt-dlp denoUpdate with brew upgrade yt-dlp.
Copy the distributed environment file and set up the DB variables
cp .env.example .envSQLite is used by default (requires the pdo_sqlite PHP extension). DB_DATABASE can be a
path relative to the project root (default database/ydownload.sqlite). Create the empty
database file at the path configured in DB_DATABASE, for the default:
touch database/ydownload.sqliteRun composer, set the key and run the migrations
composer install
php artisan key:generate # only on a fresh install: it replaces an existing APP_KEY
php artisan migrateOptional .env variables (see config/services.php):
| Variable | Default | Description |
|---|---|---|
YTDLP_BINARY |
yt-dlp |
Path to yt-dlp. Use an absolute path (/usr/local/bin/yt-dlp) when served by a web server, whose user may have a different PATH |
FFMPEG_LOCATION |
(PATH) | Path to ffmpeg, if it is not in PATH |
YTDLP_FORMAT |
bestaudio[ext=m4a]/bestaudio |
Audio format to download before converting to MP3 |
YTDLP_TIMEOUT |
300 |
Maximum seconds for a download |
When the site is served by a web server (e.g. www-data) instead of php artisan serve, it needs
write access to storage, bootstrap/cache, the SQLite file and its directory (SQLite creates
journal files next to the database):
sudo chgrp -R www-data storage bootstrap/cache database
sudo chmod -R g+rwX storage bootstrap/cache
sudo chmod g+rwx database && sudo chmod g+rw database/ydownload.sqliteOr run make permissions (set WEB_GROUP=... for a different group).
The same steps are available as make targets (run make to list them all):
make system-deps # ffmpeg, curl, unzip, yt-dlp and Deno (Ubuntu / Debian / WSL, uses sudo)
make install # composer, .env, APP_KEY, SQLite DB and migrations
make check # show versions of php, yt-dlp, deno, ffmpeg and pdo_sqlite
make ytdlp-update # update yt-dlp when downloads stop working
make serve # start the development server
make test # run the testsphp artisan serve
Just comment this line __construct of HomeController.php
//$this->middleware('auth');