Skip to main content

Ampache CLI Commands

Ampache CLI Commands

Every administrative and maintenance task in Ampache is available from the command line through bin/cli.

This page lists every command grouped by its prefix. For the migration history from the old bin/*.inc scripts see Ampache CLI.

Run the program with no arguments to see the full list, and add -h or --help to any command to see its arguments and options.

php bin/cli
php bin/cli admin:addUser --help

Commands are grouped by a prefix that describes what they touch:

  • admin: — users, modules, mail, database and other server administration
  • run: — catalogs and long-running background processes
  • cleanup: — housekeeping of statistics, art and disabled media
  • export: — writing art, playlists and catalog metadata to disk
  • print: — read-only reports printed to the terminal
  • show: — read-only information about the installation

Two more commands live in a separate binary, bin/installer, because they have to run before there is a config file to read. They are listed at the end of this page.

Most admin: and run: commands change your database, so treat them with the same care as the equivalent page in the web interface.

image

admin: server administration

Many of these commands mirror an action on an Admin page in the web interface and call the same code underneath, so a change made on the command line shows up in the browser and vice versa.

Users

CommandWhat it does
admin:addUserCreate a user account. Takes a <username> argument plus --password, --email, --website, --name and --level options. A random password is generated when none is supplied.
admin:listUsersList every user, or find one by [username] / --user <id>. --apikey prints only the API key.
admin:updateUserUpdate a single user: generate a new --apikey, --streamtoken or --rsstoken, set the --subsonic password, or change the access --level. New in Ampache 8: --subsonic.
admin:deleteUserDelete a user by [username] or --user <id>. Refuses to remove the last active administrator.
admin:enableUserEnable a disabled user.
admin:disableUserDisable a user. Refuses to disable the last active administrator.
# Create a manager-level user with a known password
php bin/cli admin:addUser jane --level 75 --password "s3cr3t" --email jane@example.com

# Rotate a user's API key
php bin/cli admin:updateUser jane --apikey

# Disable, then later delete a user
php bin/cli admin:disableUser jane
php bin/cli admin:deleteUser jane

NOTE Access Control Lists, Licenses and Catalog Filters have no CLI commands. They are managed from Admin → Access Control, Admin → Licenses and Admin → Catalog Filters in the web interface, or through the API.

Modules (plugins, catalog types and localplay)

Ampache has three kinds of pluggable module: application plugins, catalog types (the backends a catalog can use, such as subsonic or beets) and localplay controllers (players such as mpd that Ampache can drive). These mirror the Admin → Modules pages.

CommandWhat it does
admin:listModulesList every plugin, catalog type and localplay controller and whether it is installed.
admin:installPluginInstall (enable) a plugin by <name> and rebuild user preferences so its settings appear.
admin:uninstallPluginUninstall (disable) a plugin by <name>.
admin:upgradePluginUpgrade an installed plugin by <name> to the bundled version.
admin:installCatalogTypeInstall (enable) a catalog type by <type>.
admin:uninstallCatalogTypeUninstall (disable) a catalog type by <type>.
admin:installLocalplayInstall (enable) a localplay controller by <type> and set the localplay preferences for --user.
admin:uninstallLocalplayUninstall (disable) a localplay controller by <type>.
php bin/cli admin:listModules
php bin/cli admin:installPlugin lastfm
php bin/cli admin:installCatalogType subsonic
php bin/cli admin:installLocalplay mpd

See Ampache Plugins for what each plugin does.

image

Mail

CommandWhat it does
admin:mailUsersSend an e-mail to a group of users. Takes a [group] argument (all, users, admins, inactive) plus --subject and --message. Does nothing when mail is disabled or the server is in demo mode.
php bin/cli admin:mailUsers users --subject "Maintenance" --message "The server restarts at 02:00 UTC."

System administration

CommandWhat it does
admin:updateDatabaseApply any pending database migrations. Run this after upgrading Ampache. Prints what it would do; -e actually applies it.
admin:updateConfigFileRegenerate config/ampache.cfg.php, merging in any new options for your installed version. Ampache 8 ships config_version 95.
admin:updatePluginsUpgrade every installed plugin to its bundled version in one pass.
admin:updatePreferenceAccessLevelChange the access level required to edit a preference. Takes --level and needs -e to write.
admin:resetPreferencesReset preference values back to their defaults for a <username>. Takes --preset and needs -e to write.
admin:clearCacheClear a cache by [type]. Only perpetual_api_session has a lasting effect (it removes stored perpetual API sessions); the song, artist and album object caches live only for a single process.
admin:exportSchemaRegenerate the resources/sql/ampache.sql seed dump from the current database. A development/release tool; it refuses to run when migrations are pending.

run: catalogs and background processes

Catalogs

CommandWhat it does
run:addCatalogCreate a local media catalog. Takes [catalogName], [catalogPath], [mediaType] (music, video, podcast), [filePattern] and [folderPattern].
run:updateCatalogPerform catalog actions across all files: clean, add, gather art, verify and garbage-collect. With no options the defaults -ceagt are used. Accepts a [catalogName] and [catalogType].
run:updateCatalogFilePerform catalog actions for a single file. Takes <catalogName> <filePath>.
run:updateCatalogFolderPerform catalog actions for a single folder. Takes <catalogName> <folderPath>.
run:deleteCatalogDelete a catalog by <catalogId> and everything it owns.
run:enableCatalogEnable a catalog by <catalogId>.
run:disableCatalogDisable a catalog by <catalogId> without deleting it.
run:moveCatalogPathUpdate the stored file locations for a catalog after a mount point has changed.

New in Ampache 8: -s|--scan builds the Folders tree for a catalog, the same job as the Scan Folders action on the catalog page. It is available on run:updateCatalog and run:updateCatalogFolder and is not one of the -ceagt defaults, so it has to be asked for.

php bin/cli run:addCatalog music /media/music music
php bin/cli run:updateCatalog music
php bin/cli run:updateCatalog music -s
php bin/cli run:disableCatalog 3

The -v verify switch from Ampache 4 is now -e.

Background processes

CommandWhat it does
run:cronProcessRun the scheduled cron tasks. Intended to be triggered from the system cron. See CRON.
run:cacheProcessPopulate the transcode cache.
run:computeCacheRebuild the object cache tables.
run:calculateArtSizeFill in the stored width/height for art.
run:convertFilenamesConvert file names in the database to a different character set. --charset picks the target.
run:broadcastRun a UPnP broadcast.
run:websocketRun the WebSocket server used by the now-playing broadcast feature. --port defaults to 8100.
run:updateDbUpdate the database collation and character set. Dry run until -x|--execute.

cleanup: housekeeping

CommandWhat it does
cleanup:enableDisabledRe-enable every song that was previously disabled.
cleanup:songsList songs that are currently disabled; -d|--delete removes them.
cleanup:artRemove art that no longer fits the configured settings. -c drops missing files from the database, -t deletes all thumbnails.
cleanup:sortSongsMove song files into place according to the catalog sort pattern.
cleanup:consolidateStatsConsolidate old play history into summary counts and archive the detail rows. New in Ampache 8.
cleanup:restoreStatsRestore consolidated play history back from the archive. New in Ampache 8.

Everything under cleanup: is a dry run until you ask for the write. The flag is not the same on every command: cleanup:art and cleanup:sortSongs take -x|--execute, cleanup:consolidateStats and cleanup:restoreStats take -e|--execute, and cleanup:songs takes -d|--delete.

# See what would be consolidated, then actually do it
php bin/cli cleanup:consolidateStats
php bin/cli cleanup:consolidateStats -e

See Play history consolidation for what the two stats commands move around.

NOTE There is no CLI command for clearing play statistics or the now-playing list. Use Clear Stats on the Admin → Manage Catalogs page and Clear Now Playing in the admin sidebar.

export: writing files to disk

CommandWhat it does
export:catalogExport catalog metadata to a file. Takes a <file> argument and a [format] (csv or itunes); --catalog limits it to one catalog.
export:playlistExport lists to a <directory>. [type] picks albums, artists, playlists or smartlists and [extension] picks m3u, xspf or pls. --web writes stream urls instead of file paths.
export:albumArtExport album art to the catalog folders. [type] is linux or windows and sets how the metadata is written.
export:databaseArtExport all art stored in the database to the local_metadata_dir. --clear drops the database copy once the file exists.
php bin/cli export:catalog /backup/library.csv csv
CommandWhat it does
print:duplicatesPrint possible duplicate albums, artists or songs. -t|--type selects what to look for (default album).
print:tagsPrint the tags Ampache reads from a media <filename>.

show: installation information

CommandWhat it does
show:debugPrint a headless status and environment report: version, structure, PHP version, last cron run and a pass/fail list of the runtime prerequisites. Add --check-updates to also query the remote latest version.
show:versionPrint the Ampache version.
php bin/cli show:debug

image

bin/installer — before Ampache has a config

bin/installer is a second, smaller binary. Its two commands run before there is a config file or a database, which is why they are not in bin/cli and why bin/cli htaccess does not exist.

CommandWhat it does
installCreate and populate the database and write config/ampache.cfg.php. See Installation.
htaccessWrite the .htaccess files Apache reads. Nothing happens without -e, which is a dry run guard, not a default.

htaccess -e writes the two files Ampache needs, public/play/.htaccess and public/rest/.htaccess.

Without them, streaming returns 404 and every Subsonic or REST client fails.

OptionWhat it adds
-e|--executeActually write the files. Without it the command only prints its help.
-p|--publicAlso write public/.htaccess, which is optional hardening rather than something Ampache needs.
# the two files Ampache needs
php bin/installer htaccess -e

# and the optional web root file as well
php bin/installer htaccess -e -p

The web root file carries a user art redirect, blocking for private paths such as config/ and .git, and a commented-out bot filter. Ampache behaves identically without it.

NOTE -p overwrites public/.htaccess. If you uncommented the bot filtering or edited it in any other way, back it up first.

Rewrite Rules covers what each file does, what the web root file blocks, and how to check the rules are being read.

php bin/installer install -U root -P mypassword -H localhost -d ampache -u ampache -p ampachepassword -w /ampache -f

NOTE install takes -p|--ampachedbpassword, which is a different option to htaccess's -p|--public. The two commands do not share options.