Amazon.co.uk Widgets

Log in

X

Joomla has an effective command line interface (CLI)

Web apps aren't the best way to do repetitive actions or tasks with accuracy. Command line interfaces are under-rated but good solutions to this problem, and Joomla has one nowadays. You can use commands in scripts or type them in to your shell in order to accomplish routine tasks with repeatable accuracy.

It seems quite radical really to ssh into my server and set a configuration option from the command line but it is just the same security model as it would be if I using an editor.

TL:DR — The command line in Joomla is effective and lets you script common commands for better repeatability and accuracy. On a mac it takes just a couple of commands in terminal to access the Joomla CLI on your server.

Using terminal on a Mac or Linux computer to access your Joomla Server

First, you'll need to enable SSH to access your Joomla site directly from a terminal. Use your service providers tools to do this and then you can just use ssh servername -l username using the credentials from your service provider. The first time you do this it will set up a fingerprint so that ssh can verify that the server (host) you are connecting to, is the same on subsequent connections, so as to make sure that you dont try to connect to an imposter in the future.

Run your first command

Once connected change into the command line folder, something like cd public_html/cli.

Run your first command php joomla.php core:check-updates. Marvel at the results

$ php joomla.php core:check-updates

Joomla! Updates
===============

 ! [NOTE] New Joomla Version 5.0.3 is available.

What can Joomla do from the command line (CLI)?

The CLI is sort of self documenting, in that if you run it without a command using php joomla.php the output presented is a list of all the commands it knows about. If an extension has its own implementation of the command line interface it won't be shown here. There's a lot here so lets break it down a little bit. There are commands for different categories of functionality in Joomla, namely cache, config, core, database, extension, finder, scheduler, session, site, update,and user. Unsurprisingly, there are a lot of useful maintenance commands here. If you run multiple Joomla based sites then the possibility of creating your own useful scripts to perform routine functions reliably is endless, and extremely powerful when combined with the new Joomla task scheduler.

$ php joomla.php 
Joomla! (debug: No)

Usage:
  command [options] [arguments]

Options:
  -h, --help            Display the help information
  -q, --quiet           Flag indicating that all output should be silenced
  -V, --version         Displays the application version
      --ansi            Force ANSI output
      --no-ansi         Disable ANSI output
  -n, --no-interaction  Flag to disable interacting with the user
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
  help                            Show the help for a command
  list                            List the application's available commands
 cache
  cache:clean                     Clean expired cache entries
 config
  config:get                      Display the current value of a configuration option
  config:set                      Set a value for a configuration option
 core
  core:check-updates              Check for Joomla updates
  core:update                     Update Joomla
 database
  database:export                 Export the database
  database:import                 Import the database
 extension
  extension:discover              Discover extensions
  extension:discover:install      Install discovered extensions
  extension:discover:list         List discovered extensions
  extension:install               Install an extension from a URL or from a path
  extension:list                  List installed extensions
  extension:remove                Remove an extension
 finder
  finder:index                    Purges and rebuild the index
 scheduler
  scheduler:list                  List all scheduled tasks
  scheduler:run                   Run one or more scheduled tasks
  scheduler:state                 Enable, disable or trash a scheduled task
 session
  session:gc                      Perform session garbage collection
  session:metadata:gc             Perform session metadata garbage collection
 site
  site:down                       Put the site into offline mode
  site:up                         Put the site into online mode
 update
  update:extensions:check         Check for pending extension updates
  update:joomla:remove-old-files  Remove old system files
 user
  user:add                        Add a user
  user:addtogroup                 Add a user to a group
  user:delete                     Delete a user
  user:list                       List all users
  user:removefromgroup            Remove a user from a group
  user:reset-password             Change a user's password
$ 

Joomla Cache CLI command examples

Clean expired cache entries from the command line (CLI)

php joomla.php core:cache:clean.

$ php joomla.php cache:clean

Cleaning System Cache
=====================

[OK] Cache cleaned

$

Joomla Config CLI command examples

Display the current value of a configuration option from the command line (CLI)

You can get all the configuration items using php joomla.php config:get, or you can get a specific item by naming it in the command php joomla.php config:get editor.

$ php joomla.php config:get editor
 -------- ------------ 
  Option   Value       
 -------- --------- 
  editor   tinymce  
 -------- --------- 
$

Set a value for a configuration option from the command line (CLI)

You can set a value for a configuration option too php joomla.php config:set editor=codemirror. Here I am changing the default editor to codemirror.

$ php joomla.php config:set editor=codemirror

 [OK] Configuration set  
 
$ php joomla.php config:get editor
 -------- ------------
  Option   Value     
 -------- ------------ 
  editor   codemirror  
  -------- ------------ 
$

Joomla Core CLI command examples

Update Joomla from the command line (CLI)

You can update Joomla itself from the command line php joomla.php core:update.

$ php joomla.php core:update
 8/8 -- Cleaning up ...   
                         
 [OK] Joomla core updated successfully!

Joomla Database CLI command examples

Export the database from the command line (CLI)

Be careful that you run this command in the directory that you want the output to appear as it creates a lot of output files, and they should not be readable on your site by a visitor!

$ php joomla.php database:export
Exporting Database
==================

 Processing the xxxx_action_log_config table
 Exported data for xxxx_action_log_config in 0 seconds
 Processing the xxxx_action_logs table
 Exported data for xxxx_action_logs in 2 seconds
 ... (lots of output deleted and db prefix changed to xxxx)
 Processing the xxxx_workflows table
 Exported data for xxxx_workflows in 0 seconds
 
 [OK] Export completed in 9 seconds  
 
$

Joomla Extension CLI command examples

Manage extensions from the command line (CLI)

You can list installed extensions extension:list, remove an installed extension extension:remove, discover extensions using extension:discover as well as install discovered extensions extension:discover:install from a URL or a path, list discovered extensions extension:discover:list, and remove an extension.extension:remove.

$ php joomla.php extension:list 

Installed extensions.
=====================
 ----------------------------------- -------------- ----------- ----------- --------
 Name                                Extension ID   Version     Type        Active 
 ----------------------------------- -------------- ----------- ----------- --------
  com_wrapper                         1              4.0.0       component   Yes  
  com_admin                           2              4.0.0       component   Yes  
  com_banners         
  ... (further rows omitted) ...
 ----------------------------------- -------------- ----------- ----------- --------

$

Joomla Finder CLI command examples

Purges and rebuilds the index from the command line (CLI)

You can rebuild the index using php joomla.php finder:index.

$ php joomla.php finder:index  
Finder Indexer
==========================

 Starting Indexer
 Setting up Smart Search plugins
 Setup 179 items in 0.016 seconds.
  * Processed batch 1 in 1.12 seconds.
  * Processed batch 2 in 2.715 seconds.
  * Pausing processing for 1 seconds ...
  * Continuing processing of batch ...
  * Processed batch 3 in 2.742 seconds.
  * Pausing processing for 1 seconds ...
  * Continuing processing of batch ...
  * Processed batch 4 in 1.864 seconds.

Total Processing Time: 10.46 seconds.
Peak memory usage: 18,874,368 bytes

$

Joomla Scheduler CLI command examples

List all scheduled tasks from the command line (CLI)

You can list scheduler:list, run scheduler:run, and examine the state scheduler:state of scheduled tasks. Running scheduler tasks from the command line might be the most powerful aspect of the Joomla CLI.

As you can see the scheduled task list matches up, as you would expect it to.

Joomla 4.1 Scheduled Tasks admin interface
Joomla 4.1 Scheduled Tasks admin interface
$ php joomla.php scheduler:list

List Scheduled Tasks
====================

 ---- ------- ------------------- --------- ---------- 
  id   title   type                state     next run  
 ---- ------- ------------------- --------- ---------- 
  1    Sleep   Demo Task - Sleep   Enabled   DUE!      
 ---- ------- ------------------- --------- ---------- 

$

Enable, disable or trash a scheduled task from the command line (CLI)

$ php joomla.php scheduler:state
Please specify the ID of the task:
 > 1
 
 Should the state be "enable" (1), "disable" (0) or "trash" (-2):
 > 0
 
 [OK] Task ID 1 disabled.
$

Joomla Session CLI command examples

Perform session garbage collection from the command line (CLI)

Session garbage collection session:gc or session metatata garbage collection session:metadata:gc

$ php joomla.php session:gc 
Running Session Garbage Collection
==================================

 [OK] Garbage collection completed.
$

Joomla Site CLI command examples

Put the site into offline or online mode from the command line (CLI)

Take a Joomla site offline site:down or put a site online site:up

$ php joomla.php site:down
                                                                                                                      
 [OK] Configuration set                                                                                                 
                                                                                                                      
 [OK] Website is now offline  

$ php joomla.php site:up
                                                                                                                     
 [OK] Configuration set                                                                                                 

 [OK] Website is now online 

$

Joomla Update CLI command examples

Check for pending extension updates from the command line (CLI)

$ php joomla.php update:extensions:check

Fetching Extension Updates
==========================

 [OK] There are no available updates                               
 
$

Remove old system files from the command line (CLI)

$ php joomla.php update:joomla:remove-old-files

Removing Unneeded Files & Folders
=================================
 [OK] 5785 Files checked and 0 deleted 
 
 [OK] 1337 Folders checked and 0 deleted
$

Joomla User CLI command examples

Extensive Joomla user management is possible from the command line (CLI)

Add user:add, add to group user:addtogroup, delete user:delete, list user:list, remove from group user:removefromgroup, and reset a user password user:reset-password from the command line (CLI)

$ php joomla.php user:removefromgroup --username=xxxx --group=Registered

Remove user from group
======================

 [OK] Removed 'xxxx' from group 'Registered'! 

$ 

See also:
GSoC 2018 Joomla CLI Update Documentation 
Joomla 4: A Powerful CLI Application - Joomla Magazine, June 2022