Command-Line Interface

Directus CLI provides commands that allow you to perform various tasks such as installation, resetting a user's email, or upgrading the database to the most recent Directus schema.

Commands List

Name Description
install:config Create a configuration file
install:database Create the default tables and data
install:install Create initial configuration data
db:upgrade Upgrade the Database Schema
user:password Change a user password
log:prune Remove old logs files

Help

You can use the help command at any time to learn about available CLI actions:

# this will provide information about the current modules
php bin/directus help

To get more information on an specific command you can type "help" followed by the command:

# this provide information about the **install** module
php bin/directus help install

Install Module

Includes commands to install and configure Directus.

Configure Directus:

Creates the config.api.php file.

WARNING

This command will overwrite any existing default configuration file at config.api.php.

php bin/directus install:config -h <db_host> -n <db_name> -u <db_user> -p <db_pass> -e <directus_email> -s <db_unix_socket>
Option Description
t Database type. (Only mysql supported)
h Database host
P Database port
n Database name (it must already exist)
u Database user's name
p Database user's password
e (Optional) The Directus email that will be used as sender in the mailing process
s Database unix socket
c Enable/Disable CORS
N Unique Project's name
timezone API Server default timezone
f Force file overwritten

Example: http://example.local

php bin/directus install:config -h localhost -n directus -u root -p pass

Example: http://example.local/directus

php bin/directus install:config -h localhost -n directus -u root -p pass -d directus

Populate the Database Schema:

Creates all of the Directus Core tables based on the configuration files: /config/api.php.

php bin/directus install:database

Install Initial Configurations:

Create the default admin user and the site's default settings.

php bin/directus install:install -e <admin_email> -p <admin_password> -t <site_name>
Option Description
e Admin email
p Admin password
T Admin Static Auth Token
t Project title
a Project's Application URL
N Unique Project's name
timezone Admin timezone
locale Admin locale
f Recreate Directus core tables. Also remove all Directus data

Example

php bin/directus install:install -e admin@directus.local -p password -t "Directus Example"

User Module

Includes commands to manage Directus users

Change User Password:

php bin/directus user:password -e <user_email> -p <new_password>
  • user_email - The user's email
  • new_password - The user's new password

Example

php bin/directus user:password -e admin@directus.local -p newpassword

Database Module

Includes commands to manage Directus database schema

TIP

This requires that Directus has a valid connection configured in config/api.php.

WARNING

Always backup your database before running the database module to prevent data loss.

Upgrade Directus Schema

$ bin/directus db:upgrade

The command above will upgrade the default project database, to update an specific project the option N can be used.

$ bin/directus db:upgrade -N <project-name>

Log Module

Prune Old Log Files

php bin/directus log:prune <days>

<days> is optional. The default value is 30 days.

Removes all the logs that were last modified <days> ago. it uses filemtime function to determine the last modified time.

TIP

You can setup a cronjob to clean old files at a set frequency