A command-line interface for MODX 3, built with Symfony Console.
- PHP 7.4 or higher
- MODX 3.0.0 or higher
composer global require modx/cli
- Clone the repository:
git clone https://github.com/finetuned/modx-cli.git
cd modx-cli
- Install dependencies:
composer install
- Make the CLI executable:
chmod +x bin/modx
- Create a symbolic link to make the CLI available globally:
sudo ln -s $(pwd)/bin/modx /usr/local/bin/modx
modx [command] [options]
When a MODX instance is configured and set as default, many commands become available, including:
version
- Display the CLI versionsystem:info
- Get general system informationsystem:clearcache
- Clear the MODX cacheresource:getlist
- Get a list of resourcesresource:create
- Create a MODX resourceresource:update
- Update a MODX resourceuser:getlist
- Get a list of userstemplate:getlist
- Get a list of templates- And many more
To see all available commands, run:
modx list
Display the CLI version:
modx version
Get system information:
modx system:info
Clear the MODX cache:
modx system:clearcache
Get a list of resources:
modx resource:getlist
Get a list of resources with filters:
modx resource:getlist --parent=1 --context=web --published=1
Most commands in the MODX CLI require a MODX instance to be available. To see all available commands, you need to configure at least one MODX instance and set it as the default.
To add a MODX instance:
modx config:add mysite --base_path=/path/to/modx/
To set a MODX instance as the default:
modx config:set-default mysite
You can also specify a MODX instance to run a command on:
modx --site=mysite system:info
MODX CLI supports running commands on remote servers via SSH and using aliases to simplify working with multiple MODX installations.
Run commands on a remote server:
modx --ssh=user@example.com:/path/to/modx system:info
Define aliases in ~/.modx/config.yml
or modx-cli.yml
in your project directory:
@prod:
ssh: user@production-server.com:/path/to/modx
@staging:
ssh: user@staging-server.com:/path/to/modx
Use aliases to run commands:
modx @prod system:info
Define alias groups to run commands on multiple servers:
@all:
- @prod
- @staging
modx @all system:clear-cache
For more information, see SSH and Aliases Documentation.
To enable bash completion, add the following to your .bashrc
or .bash_profile
:
source /path/to/modx_completion.sh
To build the PHAR file:
composer install --no-dev
box compile
This will create a modx-cli.phar
file in the root directory.
Contributions are welcome! Please feel free to submit a Pull Request.
MIT