2017 © Pedro Peláez
 

library cli

Command line interface for Craft CMS

image

craft-cli/cli

Command line interface for Craft CMS

  • Friday, July 28, 2017
  • by rsanchez
  • Repository
  • 4 Watchers
  • 136 Stars
  • 7,745 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 20 Forks
  • 3 Open issues
  • 54 Versions
  • 8 % Grown

The README.md

Craft CLI

Command line interface for Craft CMS., (*1)

Installation

If you are on Mac, you should install via Homebrew., (*2)

brew tap rsanchez/homebrew-craft-cli
brew install craft-cli

Otherwise, you should download the phar: https://github.com/rsanchez/craft-cli/releases/latest, (*3)

php craft.phar <your:command>

See Composer Installation for alternate ways to install., (*4)

Usage

If you are using a multi-environment config, you must specify your environment either using the --environment= flag on your commands, or set the CRAFT_ENVIRONMENT env variable., (*5)

craft --environment="mysite.dev" show:config
CRAFT_ENVIRONMENT="mysite.dev" craft show:config

Craft CLI is dotenv aware, and will automagically load environment variables from a .env file in your project root (path can be customised via .craft-cli.php). You may set your Craft environment by setting a CRAFT_ENVIRONMENT variable in your .env file., (*6)

Commands

Assets Pull

Pull Asset files from a remote environment., (*7)

craft assets:pull --ssh-host=your.remote.server.com --ssh-user=yourUserName yourRemoteEnvironmentName

Assets Push

Push Asset files to a remote environment, (*8)

craft assets:push --ssh-host=your.remote.server.com --ssh-user=yourUserName yourRemoteEnvironmentName

Clear Cache

Clear all Craft caches., (*9)

craft clear:cache

Select which cache(s) to clear from an interactive list., (*10)

craft clear:cache -s

Console

Start an interactive shell., (*11)

craft console

DB Backup

Backup your database to craft/storage/backups., (*12)

craft db:backup

Backup your database to the specified path., (*13)

craft db:backup ./backup.sql

DB Create

Create a database, (*14)

craft db:create --host=localhost --port=3306 --name=yourDbName --user=yourUserName --password=yourPassword

DB Pull

Pull a remote database to the local database., (*15)

craft db:pull --ssh-host=your.remote.server.com --ssh-user=yourUserName --force yourRemoteEnvironmentName

DB Push

Push your local database to a remote database., (*16)

craft db:push --ssh-host=your.remote.server.com --ssh-user=yourUserName --force yourRemoteEnvironmentName

DB Restore

Restore the database from the most recent backup from craft/storage/backups., (*17)

craft db:restore --force

Restore the database from the specified .sql file., (*18)

craft db:restore --force ./backup.sql

Download Craft

Download Craft to the current directory., (*19)

craft download

Create the specified directory and download Craft into it., (*20)

craft download path/to/directory

Generate Command

Generate a custom command file in the specified directory., (*21)

craft generate:command your:custom_command ./commands/

Generate a custom command file with a namespace., (*22)

craft generate:command --namespace="YourSite\Command" your:custom_command ./src/YourSite/Command/

Generate a custom command with arguments and options., (*23)

craft generate:command --options --arguments your_command ./commands/

Help

Display information about a command and its arguments/options., (*24)

craft help <command>

Init

Create an .craft-cli.php config file in the current directory, (*25)

craft init

This config file is only necessary if you if you are using Custom Commands or have renamed your craft folder., (*26)

Install Craft

Download and install Craft to the current directory., (*27)

craft install

Create the specified directory and install Craft into it., (*28)

craft install path/to/directory

Install Plugin

Install a plugin from a GitHub repository., (*29)

craft install:plugin pixelandtonic/ElementApi

List

List the available commands., (*30)

craft list

Rebuild Search Indexes

craft rebuild:searchindexes

Run Tasks

Run all pending tasks., (*31)

craft run:tasks

Reset "running" (stalled) tasks and then run all tasks., (*32)

craft run:tasks --reset-running

Reset failed tasks and then run all tasks., (*33)

craft run:tasks --reset-failed

Show Config

Show all config items., (*34)

craft show:config

Show the specified config item., (*35)

craft show:config db.user

Tail

Show a tail of craft.log, (*36)

craft tail

Update Asset Indexes

craft update:assetsindexes

Configuration

Craft CLI can be configured in two ways. You may use the craft init command to generate a .craft-cli.php file. Or, if you have installed Craft CLI via composer, you may add an extra object to your composer.json and a craft-cli object within the extra object:, (*37)

{
    "extra": {
        "craft-cli": {
            "commandDirs": {
                "\\Your\\Namespace": "path/to/commands/"
            }
        }
    }
}

Custom Commands

Craft CLI custom commands are Symfony Console Command objects. You can add custom commands to your .craft-cli.php or composer.json config by adding a namespace and folder path to the commandDirs object., (*38)

You can generate a custom command file using the craft generate:command command., (*39)

Troubleshooting

Your command-line PHP cannot connect to MySQL

You can test this by running this at the command line (change the DB credentials to your actual credentials):, (*40)

php -r "var_dump(@mysql_connect('hostname', 'username', 'password', 'database_name'));"

If this prints false, then you know that your CLI PHP is not configured to connect to your database. This is frequently caused by an incorrect default MySQL socket setting., (*41)

If you are running MAMP, for instance, and are using the stock Mac OS command-line PHP, you will not be able to connect out-of-the-box. You will need to edit your /etc/php.ini (or wherever your php.ini file is located) file and change the mysql.default_socket and/or the mysqli.default_socket to /Applications/MAMP/tmp/mysql/mysql.sock., (*42)

Composer Installation

You can install globally:, (*43)

composer global require craft-cli/cli

Make sure your global composer installation is added to your PATH in your ~/.bash_profile (or ~/.profile or ~/.bashrc or ~/.zshrc) so that you may run the binary from the command line:, (*44)

export PATH=~/.composer/vendor/bin:$PATH

Or, you can install on a per project basis, rather than globally to your host system., (*45)

composer require craft-cli/cli

Then the command would be found in your vendor/bin folder, so you'd run this at your command line:, (*46)

vendor/bin/craft <your:command>

The Versions

03/09 2016

0.7.3

0.7.3.0

Command line interface for Craft CMS

  Sources   Download

The Requires

 

by Rob Sanchez

25/08 2016

0.7.2

0.7.2.0

Command line interface for Craft CMS

  Sources   Download

The Requires

 

by Rob Sanchez

18/08 2016

0.7.1

0.7.1.0

Command line interface for Craft CMS

  Sources   Download

The Requires

 

by Rob Sanchez

21/07 2016

0.7.0

0.7.0.0

Command line interface for Craft CMS

  Sources   Download

The Requires

 

by Rob Sanchez

28/06 2016

0.6.2

0.6.2.0

Command line interface for Craft CMS

  Sources   Download

The Requires

 

by Rob Sanchez

28/06 2016

0.6.1

0.6.1.0

Command line interface for Craft CMS

  Sources   Download

The Requires

 

by Rob Sanchez

27/06 2016

0.6.0

0.6.0.0

Command line interface for Craft CMS

  Sources   Download

The Requires

 

by Rob Sanchez

16/06 2016

0.5.0

0.5.0.0

Command line interface for Craft CMS

  Sources   Download

The Requires

 

by Rob Sanchez

11/06 2016

0.4.2

0.4.2.0

Command line interface for Craft CMS

  Sources   Download

The Requires

 

by Rob Sanchez

10/06 2016

0.4.1

0.4.1.0

Command line interface for Craft CMS

  Sources   Download

The Requires

 

by Rob Sanchez

10/06 2016

0.4.0

0.4.0.0

Command line interface for Craft CMS

  Sources   Download

The Requires

 

by Rob Sanchez

12/05 2016

0.3.1

0.3.1.0

Command line interface for Craft CMS

  Sources   Download

The Requires

 

by Rob Sanchez

12/05 2016

0.3.0

0.3.0.0

Command line interface for Craft CMS

  Sources   Download

The Requires

 

by Rob Sanchez

12/05 2016

0.2.5

0.2.5.0

Command line interface for Craft CMS

  Sources   Download

The Requires

 

by Rob Sanchez

11/05 2016

0.2.4

0.2.4.0

Command line interface for Craft CMS

  Sources   Download

The Requires

 

by Rob Sanchez

08/05 2016

0.2.3

0.2.3.0

Command line interface for Craft CMS

  Sources   Download

The Requires

 

by Rob Sanchez

04/05 2016

0.2.2

0.2.2.0

Command line interface for Craft CMS

  Sources   Download

The Requires

 

by Rob Sanchez

04/05 2016

0.2.1

0.2.1.0

Command line interface for Craft CMS

  Sources   Download

The Requires

 

by Rob Sanchez

04/05 2016

0.2.0

0.2.0.0

Command line interface for Craft CMS

  Sources   Download

The Requires

 

by Rob Sanchez

03/05 2016

0.1.10

0.1.10.0

Command line interface for Craft CMS

  Sources   Download

The Requires

 

by Rob Sanchez

29/04 2016

0.1.9

0.1.9.0

Command line interface for Craft CMS

  Sources   Download

The Requires

 

by Rob Sanchez

29/04 2016

0.1.8

0.1.8.0

Command line interface for Craft CMS

  Sources   Download

The Requires

 

by Rob Sanchez

29/04 2016

0.1.7

0.1.7.0

Command line interface for Craft CMS

  Sources   Download

The Requires

 

by Rob Sanchez

28/04 2016

0.1.6

0.1.6.0

Command line interface for Craft CMS

  Sources   Download

The Requires

 

by Rob Sanchez

28/04 2016

0.1.5

0.1.5.0

Command line interface for Craft CMS

  Sources   Download

The Requires

 

by Rob Sanchez

28/04 2016

0.1.4

0.1.4.0

Command line interface for Craft CMS

  Sources   Download

The Requires

 

by Rob Sanchez

28/04 2016

0.1.3

0.1.3.0

Command line interface for Craft CMS

  Sources   Download

The Requires

 

by Rob Sanchez

28/04 2016

0.1.2

0.1.2.0

Command line interface for Craft CMS

  Sources   Download

The Requires

 

by Rob Sanchez

11/12 2015

0.1.1

0.1.1.0

Command line interface for Craft CMS

  Sources   Download

The Requires

 

by Rob Sanchez

02/12 2015

0.1.0

0.1.0.0

Command line interface for Craft CMS

  Sources   Download

The Requires

 

by Rob Sanchez

19/10 2015

0.0.1

0.0.1.0

Command line interface for Craft CMS

  Sources   Download

The Requires

 

by Rob Sanchez

09/09 2015

0.0.0

0.0.0.0

Command line interface for Craft CMS

  Sources   Download

The Requires

 

by Rob Sanchez