PHPackages                             craft-cli/cli - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. craft-cli/cli

ActiveLibrary

craft-cli/cli
=============

Command line interface for Craft CMS

0.17.5(6y ago)13422.1k12[4 issues](https://github.com/rsanchez/craft-cli/issues)2PHP

Since Sep 9Pushed 6y ago3 watchersCompare

[ Source](https://github.com/rsanchez/craft-cli)[ Packagist](https://packagist.org/packages/craft-cli/cli)[ RSS](/packages/craft-cli-cli/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (9)Versions (60)Used By (2)

Craft CLI
=========

[](#craft-cli)

Command line interface for Craft CMS.

Installation
------------

[](#installation)

If you are on Mac, you should install via [Homebrew](http://brew.sh/).

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

```

Otherwise, you should download the phar:

```
php craft.phar

```

See [Composer Installation](#composer-installation) for alternate ways to install.

Usage
-----

[](#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.

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

```

```
CRAFT_ENVIRONMENT="mysite.dev" craft show:config

```

Craft CLI is [dotenv](https://github.com/vlucas/phpdotenv) 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.

Commands
--------

[](#commands)

- [`assets:pull`](#assets-pull)
- [`assets:push`](#assets-push)
- [`clear:cache`](#clear-cache)
- [`console`](#console)
- [`db:backup`](#db-backup)
- [`db:create`](#db-create)
- [`db:pull`](#db-pull)
- [`db:push`](#db-push)
- [`db:restore`](#db-restore)
- [`download`](#download-craft)
- [`generate:command`](#generate-command)
- [`help`](#help)
- [`init`](#init)
- [`install`](#install-craft)
- [`install:plugin`](#install-plugin)
- [`list`](#list)
- [`rebuild:searchindexes`](#rebuild-search-indexes)
- [`run:tasks`](#run-tasks)
- [`show:config`](#show-config)
- [`tail`](#tail)
- [`update:assetsindexes`](#update-asset-indexes)

### Assets Pull

[](#assets-pull)

Pull Asset files from a remote environment.

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

```

### Assets Push

[](#assets-push)

Push Asset files to a remote environment

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

```

### Clear Cache

[](#clear-cache)

Clear all Craft caches.

```
craft clear:cache

```

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

```
craft clear:cache -s

```

### Console

[](#console)

Start an interactive shell.

```
craft console

```

### DB Backup

[](#db-backup)

Backup your database to `craft/storage/backups`.

```
craft db:backup

```

Backup your database to the specified path.

```
craft db:backup ./backup.sql

```

### DB Create

[](#db-create)

Create a database

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

```

### DB Pull

[](#db-pull)

Pull a remote database to the local database.

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

```

### DB Push

[](#db-push)

Push your local database to a remote database.

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

```

### DB Restore

[](#db-restore)

Restore the database from the most recent backup from `craft/storage/backups`.

```
craft db:restore --force

```

Restore the database from the specified `.sql` file.

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

```

### Download Craft

[](#download-craft)

Download Craft to the current directory.

```
craft download

```

Create the specified directory and download Craft into it.

```
craft download path/to/directory

```

### Generate Command

[](#generate-command)

Generate a custom command file in the specified directory.

```
craft generate:command your:custom_command ./commands/

```

Generate a custom command file with a namespace.

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

```

Generate a custom command with arguments and options.

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

```

### Help

[](#help)

Display information about a command and its arguments/options.

```
craft help

```

### Init

[](#init)

Create an `.craft-cli.php` config file in the current directory

```
craft init

```

This config file is only necessary if you if you are using [Custom Commands](#custom-commands) or have renamed your `craft` folder.

### Install Craft

[](#install-craft)

Download and install Craft to the current directory.

```
craft install

```

Create the specified directory and install Craft into it.

```
craft install path/to/directory

```

### Install Plugin

[](#install-plugin)

Install a plugin from a GitHub repository.

```
craft install:plugin pixelandtonic/ElementApi

```

### List

[](#list)

List the available commands.

```
craft list

```

### Rebuild Search Indexes

[](#rebuild-search-indexes)

```
craft rebuild:searchindexes

```

### Run Tasks

[](#run-tasks)

Run all pending tasks.

```
craft run:tasks

```

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

```
craft run:tasks --reset-running

```

Reset failed tasks and then run all tasks.

```
craft run:tasks --reset-failed

```

### Show Config

[](#show-config)

Show all config items.

```
craft show:config

```

Show the specified config item.

```
craft show:config db.user

```

### Tail

[](#tail)

Show a tail of craft.log

```
craft tail

```

### Update Asset Indexes

[](#update-asset-indexes)

```
craft update:assetsindexes

```

Configuration
-------------

[](#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:

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

```

Custom Commands
---------------

[](#custom-commands)

Craft CLI custom commands are [Symfony Console](http://symfony.com/doc/current/components/console/introduction.html) 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.

You can generate a custom command file using the `craft generate:command` command.

Troubleshooting
---------------

[](#troubleshooting)

### Your command-line PHP cannot connect to MySQL

[](#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):

```
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.

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`.

Composer Installation
---------------------

[](#composer-installation)

You can install globally:

```
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:

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

```

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

```
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:

```
vendor/bin/craft

```

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity40

Moderate usage in the ecosystem

Community24

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 88% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~24 days

Recently: every ~39 days

Total

58

Last Release

2512d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b8af9caec12928633707185bf2c3e903ebce695656e4c6f0ac6479378d1f9110?d=identicon)[rsanchez](/maintainers/rsanchez)

---

Top Contributors

[![rsanchez](https://avatars.githubusercontent.com/u/227340?v=4)](https://github.com/rsanchez "rsanchez (198 commits)")[![dnunez24](https://avatars.githubusercontent.com/u/323802?v=4)](https://github.com/dnunez24 "dnunez24 (8 commits)")[![tomdavies](https://avatars.githubusercontent.com/u/136308?v=4)](https://github.com/tomdavies "tomdavies (6 commits)")[![diggy](https://avatars.githubusercontent.com/u/1071337?v=4)](https://github.com/diggy "diggy (4 commits)")[![scrodde](https://avatars.githubusercontent.com/u/211272?v=4)](https://github.com/scrodde "scrodde (4 commits)")[![bgrrtt](https://avatars.githubusercontent.com/u/13173779?v=4)](https://github.com/bgrrtt "bgrrtt (2 commits)")[![mattstauffer](https://avatars.githubusercontent.com/u/151829?v=4)](https://github.com/mattstauffer "mattstauffer (1 commits)")[![leevigraham](https://avatars.githubusercontent.com/u/25124?v=4)](https://github.com/leevigraham "leevigraham (1 commits)")[![eriweb](https://avatars.githubusercontent.com/u/6181934?v=4)](https://github.com/eriweb "eriweb (1 commits)")

---

Tags

craftcraft-cmscraftcms

### Embed Badge

![Health badge](/badges/craft-cli-cli/health.svg)

```
[![Health](https://phpackages.com/badges/craft-cli-cli/health.svg)](https://phpackages.com/packages/craft-cli-cli)
```

###  Alternatives

[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.4k37.3k](/packages/matomo-matomo)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[laravel-zero/framework

The Laravel Zero Framework.

3371.4M369](/packages/laravel-zero-framework)[drupal/core

Drupal is an open source content management platform powering millions of websites and applications.

19562.3M1.3k](/packages/drupal-core)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
