---
title: "Harnessing Acquia CLI for Drupal Dev"
date: "2022-06-17T17:10:48+00:00"
summary:
image:
type: "article"
url: "/acquia-cloud-platform/add-ons/acquia-cli/help/88451-harnessing-acquia-cli-drupal-dev"
id: "34b93484-7788-4261-932a-3009e2f0d64f"
---

[Acquia CLI](https://github.com/acquia/cli) is a free and open source Command-Line Interface for macOS, Linux, and Windows that makes it easy for developers to access and manage Acquia Products and Services without leaving the terminal.

With Acquia CLI, you can run [Drush](https://www.drush.org/latest/) commands remotely, tail logs from your Acquia-hosted applications, create and manage teams and applications on the Acquia Cloud Platform, and much more. Every single [Acquia Cloud API](https://cloudapi-docs.acquia.com/) and [Acquia Cloud Site Factory API](https://docs.acquia.com/site-factory/site-factory-api) endpoint has a corresponding Acquia CLI command. You can run it interactively from a local or [Cloud IDE](https://www.acquia.com/products/drupal-cloud/cloud-ide) terminal or integrate it into your continuous integration workflow using its parameterized input and JSON output.

Note

The 2.0 version of Acquia CLI introduces Acquia Cloud Site Factory commands and full support for PHP 8.1. Download and install Acquia CLI version 2.0 now. If you're already using version 1, just run acli update.

In this post, we will walk through a few examples of how to use the power of Acquia CLI to accelerate the development and maintenance of your Drupal application.

Getting started with Acquia CLI
-------------------------------

To get started with Acquia CLI follow the simple [installation instructions](/acquia-cloud-platform/add-ons/acquia-cli/acquia-cli-installation "Acquia CLI installation"). Then make sure to [link your application to the Acquia Cloud Platform](/node/55984) via the Cloud Platform API and SSH.

Finally, run `acli list` to see [everything it can do](https://docs.acquia.com/acquia-cloud-platform/add-ons/acquia-cli/commands).

Acquia CLI accelerates Drupal development and debugging
-------------------------------------------------------

Imagine that you're troubleshooting a problem with your Drupal application; let's see how Acquia CLI can help.

### Calling the Acquia Cloud Platform API and getting help

As a seasoned developer, you know that a cache clear can fix just about anything, so let's start by clearing Varnish. Run `acli api:list` to get a list of available API commands and you'll see the one we want: `api:environments:domain-clear-caches`.

Let's see how to run it by using the help command: `acli help api:environments:domain-clear-caches`

![Terminal showing command-line instructions for clearing caches in a specified domain, with usage, arguments, and options details.](https://acquia.widen.net/content/eywhzdhpsb/web/url_47ff11bb71d8e80fc007d8193d785527.webp?v=f4eb28f4-1b03-4c12-8167-ca3c44388567)

To clear caches, we see that we need to provide an environmentId and domain to clear. Acquia CLI supports an `environmentId` in the form of a UUID, as used by Cloud API, or a more user-friendly environment alias in the form of a site name and environment, which will be very familiar to Drush users. Use `acli sa` to view available aliases for an application.

![Terminal displaying a table with application details: names, environment aliases, and UUIDs for DevX Canary environments.](https://acquia.widen.net/content/3ytmoiluif/web/url_9e093b12d7ae957949c482b1931deada.webp?v=f7d86ae7-10fd-4420-a2cf-148b877df645)

In this example, either of the following commands would have the same effect of clearing Varnish caches:

*   `acli api:environments:domain-clear-caches 12-d314739e-296f-11e9-b210-d663bd873d93 example.com`
*   `acli api:environments:domain-clear-caches myapp.dev example.com`

### Running Drush and SSH commands

Let's imagine that clearing Varnish caches didn't help, so we'll next try clearing Drupal application caches. Ordinarily this would require setting up Drush aliases for each site ahead of time, but Acquia CLI can run Drush commands on the remote environment for you without any aliases. You don't even need to download or install Drush. Simply use the environment alias as before: `acli remote:drush myapp.dev -- cr`

![Terminal screenshot showing a successful cache rebuild and closed SSH connection for a Drupal project.](https://acquia.widen.net/content/yzs4zueidv/web/url_3a789237d44b11522146d10b9a19ba21.webp?v=961f5b00-fe34-4881-b566-6cc4739493c1)

If you prefer, you could accomplish the same thing using a variety of other Acquia CLI commands:

*   Open a shell on your application using SSH: `acli remote:ssh myapp.dev` and then run `drush @myapp.dev cr`
*   Run a command against your application using SSH: `acli remote:ssh myapp.dev drush @myapp.dev cr`
*   Download Drush aliases for your application and then run Drush locally: `acli remote:aliases:download` and then run `drush @myapp.dev cr`

### Tailing logs

Let's imagine clearing Drupal caches didn't work eitherit's time to do a bit of debugging. Let's see what's going on by tailing logs with {{acli log:tail}}. Once you've selected the application, environment, and logs to tail, Acquia CLI will continuously stream the output of those log files as the servers receive new requests.

![Terminal window displaying log options and streaming logs for a Drupal project, with highlighted commands and output details.](https://acquia.widen.net/content/xnfa7iwefe/web/url_340e39eae3ad2534ea30c4a7b76f24e2.webp?v=d5545041-1db6-4fbe-bd0f-040f4f2b08b2)

You can now interact with your application and watch the messages stream in to diagnose the issue.

### Developing with a Cloud IDE

Now that Acquia CLI has helped us to identify the bug, we're going to use an Acquia Cloud IDE to develop the fix. You can quickly create a new IDE (if you don't already have one) by running `acli ide:create` and giving the new IDE a name. Within a few seconds, the new IDE will be provisioned and you can open the provided link in your browser.

### Pushing and pulling code and files

The Acquia Cloud IDE comes initialized with an empty project workspace, but it's very simple to pull in the code, files, and database from an Acquia Cloud Platform environment using Acquia CLI. Run `acli pull` to copy everything, or `acli pull:code`, `acli pull:database`, or `acli pull:files` for more granular control.

Note that the `acli pull` command is currently only available in [Acquia Cloud IDE](https://www.acquia.com/products/drupal-cloud/cloud-ide) and [Lando](https://lando.dev/) environments.

Now you have an exact copy of the Acquia Cloud Platform environment inside of your IDE, allowing you to replicate the user experience, develop features, and squash bugs. Acquia Cloud IDE even has out-of-the-box code scanning (provided by [Intelephense](https://open-vsx.org/extension/bmewburn/vscode-intelephense-client)) that can help you identify problems and develop better code.

Once you've made the fix and you're ready to deploy a change back to an Acquia Cloud Platform environment, you you have a few options:

If you are using Code Studio, just `git push` to Code Studio and let it handle testing, staging, and artifact creation for you.

If you're following Acquia's best practices of not committing third-party dependencies (such as the vendor directory) to your source Git repository, you can run the `acli push:artifact` command. It will build a deployment artifact (including vendor directories) and push it to a particular environment.

![Screenshot of a terminal displaying instructions for using the `push:artifact` command in Acquia Cloud, detailing usage, arguments, and options.](https://acquia.widen.net/content/g3xpprfij3/web/url_89f49b604439473782bd006316bff907.webp?v=797d7f8d-afb5-44a5-b030-a0ab4df1991b)

If you are committing everything to Git Acquia CLI can still help deploy code. First commit your changes, then use the Acquia Cloud Platform API to deploy the new Git commit to an Acquia Cloud Platform environment.

![Terminal screenshot showing code-switch command usage and options for switching branches in a Drupal project environment.](https://acquia.widen.net/content/mupbd6cpal/web/url_5c08d3a8fcfd445e7586d2b96c5ae113.webp?v=2bdea86e-eea6-4907-94f4-53d7a86585f0)

### Next steps

You've seen how Acquia CLI helps with day-to-day development and debugging via its human-readable interfaces, but it also has a number of commands, input parameters, and output options that make it useful for automation and scripting, such as in Continuous Integration (CI) and Continuous Delivery (CD) workflows.

For instance, it's often useful in CI environments to force scripts to run non-interactively, get verbose output or suppress output entirely, or suppress ANSI color codes; this can be achieved using the `--quiet`, `--no-ansi`, `--no-interaction`, and `--verbose` flags, which are available for every command.

Many commands support even more parameters; use the `--help` flag with any command to discover these.

Additionally, API commands return JSON output that can be piped to tools like [jq](https://stedolan.github.io/jq/) to extract individual fields. If you have `jq` installed, try running `acli api:accounts:find | jq â.company'` to retrieve the company associated with your Acquia Cloud Platform account.

![A terminal window displays a script that prints "Hello, World!" in colorful, animated text using Python code.](https://acquia.widen.net/content/61qd3wjuui/web/url_8b66e47b3e311e63657f91ca4329ec5d.png?animate=true&v=1fdf1812-c59a-444f-83ac-ccd35262c41f)

Complex queries and filters can also be used with `jq`. For instance, you can run `acli api:distributions:list | jq .[0]` to retrieve the first available Drupal Cloud distribution.

Find more examples of JSON integrations at [Examples of handling a JSON response](https://docs.acquia.com/acquia-cloud-platform/add-ons/acquia-cli/examples-handling-json-response).