> For the complete documentation index, see [llms.txt](https://learnphp.gitbook.io/learnphp/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://learnphp.gitbook.io/learnphp/wordpress/installing-wp-cli-in-windows-ok.md).

# Installing WP-CLI in Windows (ok)

Sử dụng: [https://wp-cli.org](https://wp-cli.org/)

Chú ý:&#x20;

<figure><img src="/files/HuGkrHjIOPXVOeoQXDaQ" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/jiaC0NZXmr2mq4f1p3Yx" alt=""><figcaption></figcaption></figure>

## Đây cách này hay dùng (nó tạo ra 1 file upload duy nhất)

<figure><img src="/files/6txxBdpZxsMkegaq5Hcz" alt=""><figcaption><p>wp media regenerate --yes &#x26;&#x26; $default_sizes = [];</p></figcaption></figure>

Ta thấy nó tạo duy nhất 1 link

<figure><img src="/files/H4uFhPfAGXnuPgL9gzyB" alt=""><figcaption></figcaption></figure>

Kể cả shop cũng vậy

<figure><img src="/files/1KwHAI9nxOcLwcuiluy6" alt=""><figcaption></figcaption></figure>

Trong back-end cũng hiển thị 1 ảnh chỗ thumbnail

<figure><img src="/files/7CqzhnULalteYJkS6kdT" alt=""><figcaption></figcaption></figure>

Rồi ta tắt đi và thực hiện lại nó lại hoạt động

<figure><img src="/files/fy5IiSNQguV9EzxgrBXM" alt=""><figcaption></figcaption></figure>

Đôi khi nó hoạt động như điên ta chỉ cần tắt trong functions.php nó hoạt động không như lúc trước ta cần phải vào media.php cần chú ý

<figure><img src="/files/KGOUyiRM6EO09l7GzBec" alt=""><figcaption></figcaption></figure>

Ta thử up  1 ảnh xem sao nó đúng là chỉ tạo 1 ảnh

<figure><img src="/files/hwE9H3wdqLK6eoq6Z9kt" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/KoJgk8kx8DtjTTbGFbou" alt=""><figcaption></figcaption></figure>

Hiện tại không hiểu sao nó chỉ chạy cách 2

<figure><img src="/files/J4VJxHv5tEZh7swwJ9Lo" alt=""><figcaption></figcaption></figure>

### Cách 1: dùng 1 lệnh `composer global require wp-cli/wp-cli`

If you're seeing "zsh: command not found: wp" when trying to use WP-CLI in your site shell, it means that the WP-CLI tool isn't installed or properly configured on your system, and you need to install it before you can use its commands within your site shell. How to Fix:

* **Install WP-CLI:**
  * **Using Composer:**
    * Open your terminal and navigate to your WordPress root directory.
    * Run the command: `composer global require wp-cli/wp-cli`
  * **Manually (on Linux/macOS):**
    * Download the latest WP-CLI package from the official website.
    * Extract the archive and place the `wp` executable file in a directory within your system path (e.g., `/usr/local/bin`).&#x20;

Things to Check:

* **Path Variable:**
  * Ensure that the directory containing the `wp` executable is added to your system's `PATH` environment variable.
  * You can check this by running `echo $PATH` in your terminal.
* **Site Shell Access:**
  * Verify that your site shell is properly configured to access the correct WordPress directory on your server where WP-CLI should be available.
* **Permissions:**
  * Make sure you have the necessary permissions to execute the `wp` command.&#x20;

Troubleshooting Steps:

* **Check Installation:**
  * Try running `wp --version` in your terminal. If it returns information about the WP-CLI version, it's installed correctly.
* **Re-source Environment:**
  * If you recently installed WP-CLI, try re-sourcing your shell configuration file (e.g., `.bash_profile` or `.zshrc`) to update your environment variables.
* **Specific Environment Issues:**
  * **Local Development:** If you're using a local development environment like Local by Flywheel, check their documentation for specific instructions on installing and using WP-CLI.&#x20;

### Cách 2: Cài bằng cách tải file về.

{% file src="/files/bWmlEQ8uhUcBIR09UX0x" %}

C:\wp-cli\wp.bat

```
@ECHO OFF
php "C:/wp-cli/wp-cli.phar" %*
```

![](/files/-MOU9Rm4Md4cxVzN8hCK)

```
C:\wp-cli
C:\xampp\php
```

```
wp --info
```

![](/files/-MOU9fGnMpZI1ShxfgyN)

![](/files/-MOU9i6hAiBNxqBgijfl)

Ví dụ:

![](/files/-MOUI8jYHrSFM_YYvd_N)

<https://developer.wordpress.org/cli/commands/plugin/install/>

```
wp plugin install bbpress --activate
```

![](/files/-MOUIHO1SZ-QuMJRKOP7)

Cài đặt trên git

```
chmod +x wp-cli.phar
mv wp-cli.phar /usr/local/bin/wp
wp --info
```

![](/files/-MOUJOp2qgDJEI02Mik3)

<https://developer.wordpress.org/cli/commands/post/create/>

## Config

{% embed url="<https://make.wordpress.org/cli/handbook/references/config/>" %}

C:\xampp\htdocs\example\wp-cli.yml

```
# Global parameter defaults
path: C:/xampp/htdocs/example
url: http://localhost/example
user: admin
color: false
disabled_commands:
  - db drop
  - plugin install
require:
  - path-to/command.php

# Subcommand defaults (e.g. `wp config create`)
config create:
    dbuser: root
    dbpass: 
    extra-php: |
        define( 'WP_DEBUG', true );
        define( 'WP_POST_REVISIONS', 50 );

# Aliases to other WordPress installs (e.g. `wp @staging rewrite flush`)
# An alias can include 'user', 'url', 'path', 'ssh', or 'http'
@staging:
    ssh: wpcli@staging.wp-cli.org
    user: wpcli
    path: /srv/www/staging.wp-cli.org
@production:
    ssh: wpcli@wp-cli.org:2222
    user: wpcli
    path: /srv/www/wp-cli.org

# Aliases can reference other aliases to create alias groups
# Alias groups can be nested
@both:
 - @staging
 - @production

# '_' is a special value denoting configuration options for this wp-cli.yml
_:
    # Merge subcommand defaults from the upstream config.yml, instead of overriding
    merge: true
    # Inherit configuration from an arbitrary YAML file
    inherit: prod.yml

```

![](/files/-MOUMLzYjX-cYkEdAVd1)

{% embed url="<https://developer.wordpress.org/cli/commands/post/create/>" %}

![](/files/-MOUMZ09xFDqJ8_QtYzi)

```
 wp post create --post_type=post --post_author='wordpress' --post_title='A future post' --post_status=future --post_date='2020-12-01 07:00:00'
```

![](/files/-MOUNxFC0Y1f5lBLNYBM)

## Quick Start&#x20;

<https://make.wordpress.org/cli/handbook/guides/quick-start/>

```
wp core download --path=wpclidemo.dev
```
