By Dan Atrill on Sunday, 21 September 2025
Category: September

Your Command is My Wish - using the command line in Joomla

Joomla comes with a handy collection of commands that can be run from a terminal window which can possibly save time for busy site admins.

This is an article about using the command line in the terminal window, and when you use the terminal window one often used phrase is: ”with great power comes great responsibility“. If you’re going to try anything, please use these commands carefully

I am a big fan of CRON jobs and how they can help automate the management of my websites. So for example, when I’m setting a backup using Akeeba, I use the information provided to create a CRON job for offsite backups. If you look at the commands Akeeba provide, they utilise command instructions. And in a nutshell that’s where my curiosity for Joomla’s CLI command line came from.

“CLI commands are often quicker or more convenient than equivalents accomplished through the Joomla (or cPanel) Administrator interface.” - Using the CLI from Joomla Docs

Getting started

To make use of the command line in Joomla, we need SSH access to the web server. This may not always be possible on shared hosting. It may also take a little bit of setting up to be able to get access from the command line from your own terminal window. In some cPanel hosting there is a Terminal option however that might sidestep some setup.

Assuming that you can use the terminal on your web server, let’s look at where we might be able to run command line instructions for Joomla.

All the commands that follow are run from the website’s document root. You can alternatively navigate to the cli/ directory and run as php joomla.php {command}, especially if Joomla is installed in another directory.

Changing user passwords

I’ve always had a bit of a problem changing user passwords, and some of that is down to my browser insisting on auto-filling details. In one extreme case it resulted in the username being changed. A different method for changing user passwords might be to amend them via PhpMyAdmin and MD5 hashing the password. Sometimes even that doesn’t work for me, I don’t why. So having a command line instruction that can change the user password makes a lot of sense to me.

Here’s an example (assuming you’re in the site’s document root):

php cli/joomla.php user:reset-password

You’ll need to know the username as the prompt that appears asks for it, and there's a command for listing users too.

Please enter a username: { valid username }

Please enter a new password: { new password }

This is super simple, but it also seems to bypass any validation regarding complexity or minimum length. I could, if I really wanted to, set the password from the command line, to be one letter long and it would be accept the changed password. Use this command with a lot of care.

List all the commands available

It’s quite simple to find all the commands available using php cli/joomla.php list

You’ll see all sorts of commands, including an option to add a user via user:add, a quick means of taking the site offline via site:down, listing extensions with extension:list

Scheduled Tasks

Joomla Updates

Using php cli/joomla.php scheduler:list I can see if my installation needs updating.

And with php cli/joomla.php core:update this task is quickly done.

There are also options to install extensions, and to list extensions that need updating, php cli/joomla.php update:extensions:check, another to remove an extension (if you know the ID of the extension which is found by running php cli/joomla.php extension:list) but no command exists to update extensions.

Clearing the cache

I have a specific requirement to regularly clear the cache on one particular website. Content is updated automatically and I need to make sure that the latest information displays on my site. So using the cache command line instruction via a CRON job means I can clear the expired cache without having to go into the dashboard, or in fact have any interaction with the site.

Here’s my example:

/usr/local/bin/php /home/examplesite/public_html/cli/joomla.php -n -q cache:clean

You may find there are additional tasks covering backups and cleanups in System > Manage > Scheduled Tasks depending on what other extensions you have installed.

Quickly add a new user

This is a really useful command as it’s sometimes necessary to add new users. My own experience (and I really need to sort out my own browser foibles) is that switching tabs in the user form can reset the username.

So php cli/joomla.php add:user takes me through a few quick questions, on the command line where it asks for username, full name, email address, password and usergroup. And that’s it. In less than a minute you can add a new user. And if you look carefully at the last question, it allows you to add the user to more than one user group by separating the group IDs with a comma in your response.

My next question was, what if I needed to amend the user? I can change their password, remove them from a group or delete them but other tasks still need to be done from within the Users interface in Admin.

Update config settings

You can change individual settings of the config, which might be handy if you’re taking the site live after a period of development to make it indexable.

php cli/joomla.php config:set robots="index,follow"

But as with amending configuration.php, anything you type will be used, so make sure it’s correct otherwise you could end up with a Server 500 error, broken navigation or a lost connection to the database.

Help!

Using the -h or –help switch in your command brings up notes on usage. I found this helpful when considering exporting a copy of the database as it gives me options to save to a particular folder and also to create a zip file, and the syntax. By default it would create a series of XML files in the site root, so read the notes carefully to avoid any fiddly tidy-ups.

My own export command, using php cli/joomla.php database:export --folder=tmp --zip did exactly what I needed. And as you’d expect, there’s an import command too, with corresponding help to show options.

You can also list the commands for a particular “namespace”, for example user, by entering php cli/joomla.php list user

Conclusion

I’m all for helpful shortcuts to perform common maintenance tasks, so using Joomla‘s CLI I can easily perform tasks without even having to login to the dashboard. It's all done over a secure connection accessing my website via the terminal window on my computer, or via cPanel. This is a really useful toolkit for website admins.

For a full list of commands go to: https://docs.joomla.org/J4.x:Using_the_CLI

Further Reading

https://www.ezone.co.uk/cms/joomla-cli.html

https://docs.joomla.org/J4.x:Writing_A_CLI_Application

https://docs.joomla.org/J4.x:Using_the_CLI

Leave Comments