{"id":20742696,"url":"https://github.com/itinerisltd/trellis_install_wp_cli_via_composer","last_synced_at":"2025-04-24T05:13:00.037Z","repository":{"id":94987545,"uuid":"233420669","full_name":"ItinerisLtd/trellis_install_wp_cli_via_composer","owner":"ItinerisLtd","description":"Install WP-CLI via composer on Trellis servers","archived":false,"fork":false,"pushed_at":"2020-01-19T18:03:46.000Z","size":31,"stargazers_count":13,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-24T05:12:47.165Z","etag":null,"topics":["ansible-galaxy","composer","trellis","wordpress","wp-cli"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ItinerisLtd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-01-12T16:16:01.000Z","updated_at":"2023-05-10T20:34:17.000Z","dependencies_parsed_at":"2023-03-24T08:31:07.940Z","dependency_job_id":null,"html_url":"https://github.com/ItinerisLtd/trellis_install_wp_cli_via_composer","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ItinerisLtd%2Ftrellis_install_wp_cli_via_composer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ItinerisLtd%2Ftrellis_install_wp_cli_via_composer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ItinerisLtd%2Ftrellis_install_wp_cli_via_composer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ItinerisLtd%2Ftrellis_install_wp_cli_via_composer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ItinerisLtd","download_url":"https://codeload.github.com/ItinerisLtd/trellis_install_wp_cli_via_composer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250566516,"owners_count":21451233,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansible-galaxy","composer","trellis","wordpress","wp-cli"],"created_at":"2024-11-17T07:07:05.062Z","updated_at":"2025-04-24T05:13:00.030Z","avatar_url":"https://github.com/ItinerisLtd.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# trellis_install_wp_cli_via_composer\n\n[![Ansible Role](https://img.shields.io/ansible/role/45815?style=flat-square)](https://galaxy.ansible.com/ItinerisLtd/trellis_install_wp_cli_via_composer)\n[![GitHub tag (latest SemVer)](https://img.shields.io/github/v/tag/itinerisltd/trellis_install_wp_cli_via_composer?style=flat-square)](https://github.com/ItinerisLtd/trellis_install_wp_cli_via_composer/releases)\n[![Ansible Role](https://img.shields.io/ansible/role/d/45815?style=flat-square)](https://galaxy.ansible.com/ItinerisLtd/trellis_install_wp_cli_via_composer)\n[![CircleCI](https://circleci.com/gh/ItinerisLtd/trellis_install_wp_cli_via_composer.svg?style=svg)](https://circleci.com/gh/ItinerisLtd/trellis_install_wp_cli_via_composer)\n[![Ansible Quality Score](https://img.shields.io/ansible/quality/45815?style=flat-square)](https://galaxy.ansible.com/ItinerisLtd/trellis_install_wp_cli_via_composer)\n[![GitHub License](https://img.shields.io/github/license/itinerisltd/trellis_install_wp_cli_via_composer.svg?style=flat-square)](https://github.com/ItinerisLtd/trellis_install_wp_cli_via_composer/blob/master/LICENSE)\n[![Hire Itineris](https://img.shields.io/badge/hire-Itineris-ff69b4.svg?style=flat-square)](https://www.itineris.co.uk/contact/)\n[![Twitter Follow @itineris_ltd](https://img.shields.io/twitter/follow/itineris_ltd?style=flat-square\u0026color=1da1f2)](https://twitter.com/itineris_ltd)\n[![Twitter Follow @TangRufus](https://img.shields.io/twitter/follow/TangRufus?style=flat-square\u0026color=1da1f2)](https://twitter.com/tangrufus)\n\nInstall WP-CLI via composer on Trellis servers.\n\n\u003c!-- START doctoc generated TOC please keep comment here to allow auto update --\u003e\n\u003c!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --\u003e\n\n\n- [Goal](#goal)\n  - [The Problem](#the-problem)\n  - [The Solution](#the-solution)\n- [Role Variables](#role-variables)\n- [Requirements](#requirements)\n- [Installation](#installation)\n- [FAQ](#faq)\n  - [How to install certain commands only instead of the whole WP-CLI bundle?](#how-to-install-certain-commands-only-instead-of-the-whole-wp-cli-bundle)\n  - [What to do when composer couldn't install packages because of  conflicting version constraints?](#what-to-do-when-composer-couldnt-install-packages-because-of--conflicting-version-constraints)\n  - [How to verify WP-CLI is installed via composer?](#how-to-verify-wp-cli-is-installed-via-composer)\n  - [Is it idempotent or deterministic?](#is-it-idempotent-or-deterministic)\n  - [It looks awesome. Where can I find more goodies like this?](#it-looks-awesome-where-can-i-find-more-goodies-like-this)\n  - [Where can I give :star::star::star::star::star: reviews?](#where-can-i-give-starstarstarstarstar-reviews)\n- [Testing](#testing)\n- [Feedback](#feedback)\n- [Security](#security)\n- [Credits](#credits)\n- [License](#license)\n\n\u003c!-- END doctoc generated TOC please keep comment here to allow auto update --\u003e\n\n## Goal\n\n### The Problem\n\n\u003e [Since WP-CLI v2.0.0,] the most problematic set of the dependencies, the hard requirement on an old version of Symfony, is gone. The only Symfony component we still have (yet) is `symfony/finder`, as there’s no upper version limit for that one.\n\u003e\n\u003e -- https://make.wordpress.org/cli/2018/08/08/wp-cli-v2-0-0-release-notes/\n\nHowever, the phar bundles with [WP-CLI's dependencies](https://github.com/wp-cli/wp-cli/blob/bc37f66e25b9992813b0c50b933aefbf88718e6a/composer.lock). Those dependencies' always being loaded from the phar. As a result, their versions are _locked_.\n\nFor example: WP-CLI v2.4.0 phar bundles with [`symfony/process` v2.8.5](https://github.com/wp-cli/wp-cli-bundle/blob/v2.4.0/composer.lock#L1205-L1206) (as a dependency of `symfony/finder`). Assume we have `my-awesome-command` which requires `symfony/process:5.0.0`. `$ wp package install my-awesome-command` installs `symfony/process` v5.0.0 as expected. However, `symfony/process` v2.8.5 (from the WP-CLI phar) is always used; the newer version of `symfony/process` (which required by `my-awesome-command`) is being ignored. Thus, `my-awesome-command` fails when trying to use `symfony/process`.\n\n```sh-session\n$ wp shell\n\nwp\u003e $reflector = new \\ReflectionClass('Symfony\\Component\\Process\\Process');\n=\u003e object(ReflectionClass)#2801 (1) {\n  [\"name\"]=\u003e\n  string(33) \"Symfony\\Component\\Process\\Process\"\n}\nwp\u003e echo $reflector-\u003egetFileName(); // Note that it is loaded form the WP-CLI phar.\nphar:///usr/bin/wp/vendor/symfony/process/Process.php\n```\n\nThis problem affects `symfony/finder` and its dependencies.\n\n### The Solution\n\n[Installing WP-CLI via composer](https://make.wordpress.org/cli/handbook/installing/#installing-via-composer) resolves the problem.\n\n```sh-session\n$ wp shell\n\nwp\u003e $reflector = new \\ReflectionClass('Symfony\\Component\\Process\\Process');\n=\u003e object(ReflectionClass)#2801 (1) {\n  [\"name\"]=\u003e\n  string(33) \"Symfony\\Component\\Process\\Process\"\n}\nwp\u003e echo $reflector-\u003egetFileName(); // Note that it is loaded form composer's vendor folder.\n/home/web/.composer/vendor/symfony/process/Process.php\n```\n\n## Role Variables\n\n```yaml\n# Composer packages to be removed before installing WP-CLI\n# Default: []\nwp_cli_composer_global_remove_packages:\n  - wp-cli/wp-cli-bundle\n  - psy/psysh\n\n# Composer packages to be installed\n# Default: \"wp-cli/wp-cli-bundle:{{ wp_cli_version }}\"\nwp_cli_composer_global_require_packages:\n  - \"wp-cli/wp-cli:2.4.0\"\n  - \"wp-cli/package-command:^2\"\n  - \"psy/psysh:^0.9.12\"\n  - \"xxx/yyy:'^1.2.3 || ^2.2.3'\"\n\n# WP-CLI package to be installed\n# Default: []\n# Taken form https://github.com/roots/trellis/blob/4425669bab0665f0c9aed92c80eb9b8c54f63e85/roles/wp-cli/defaults/main.yml#L10\nwp_cli_packages:\n  - \"typisttech/image-optimize-command:@stable\"\n  - \"git@github.com:Yoast/wp-cli-faker.git\"\n\n# WP-CLI path\n# Default: /usr/bin/wp\n# Taken form https://github.com/roots/trellis/blob/4425669bab0665f0c9aed92c80eb9b8c54f63e85/roles/wp-cli/defaults/main.yml#L3\nwp_cli_bin_path: /usr/bin/wp\n\n# WP-CLI bash completion path\n# Default: /etc/bash_completion.d/wp-completion.bash\n# Taken form https://github.com/roots/trellis/blob/4425669bab0665f0c9aed92c80eb9b8c54f63e85/roles/wp-cli/defaults/main.yml#L9\nwp_cli_completion_path: /etc/bash_completion.d/wp-completion.bash\n```\n\n## Requirements\n\n- [Trellis](https://github.com/roots/trellis) v1.3.0 or later\n- Ansible v2.7.0 or later\n- Python v3.7.6 or later\n\n## Installation\n\n1. Add `itinerisltd.trellis_install_wp_cli_via_composer` to `galaxy.yml`\n    ```diff\n      # galaxy.yml\n\n    + - src: itinerisltd.trellis_install_wp_cli_via_composer\n    + version: XXX.YYY.ZZZ # Check for latest version!\n    ```\n\n2. Replace `wp-cli` role with `itinerisltd.trellis_install_wp_cli_via_composer`\n    ```diff\n      # server.yml\n\n    - - { role: wp-cli, tags: [wp-cli] }\n    + - { role: itinerisltd.trellis_install_wp_cli_via_composer, tags: [wp-cli] }\n    ```\n\n3. Install galaxy roles\n    ```bash\n    trellis galaxy install\n    # Alternatively\n    ansible-galaxy install -r galaxy.yml --force\n    ```\n\n4. Re-provision\n    ```bash\n    trellis provision production\n    # Alternatively\n    ansible-playbook server.yml -e env=production\n    ```\n\n## FAQ\n\n### How to install certain commands only instead of the whole WP-CLI bundle?\n\nBy default, the whole WP-CLI bundle ([`wp-cli/wp-cli-bundle`](https://packagist.org/packages/wp-cli/wp-cli-bundle)) installed. If you want to keep your servers _lean_, install command packages selectively:\n\n```yaml\nwp_cli_composer_global_remove_packages:\n  - wp-cli/wp-cli-bundle\n\nwp_cli_composer_global_require_packages:\n  # Required: WP-CLI framework\n  - \"wp-cli/wp-cli:^2.4\"\n  # Only install commands you need:\n  - \"wp-cli/core-command:^2\"\n  - \"wp-cli/cron-command:^2\"\n  - \"wp-cli/db-command:^2\"\n  - \"wp-cli/package-command:^2\"\n```\n\n### What to do when composer couldn't install packages because of  conflicting version constraints?\n\nDouble check existing composer packages. Then, change [version constraints](https://getcomposer.org/doc/articles/versions.md) via [role variables](#role-variables). You might need to uninstall some packages.\n\nThese commands are your friends:\n\n```bash\ncomposer global show\ncat $(composer config --global --absolute home)/composer.json\n\nwp package list\ncat $(wp package path)/composer.json\n```\n\n### How to verify WP-CLI is installed via composer?\n\n```sh-session\n# Bad: Installed via Trellis, i.e: the phar\n$ wp cli info\nWP-CLI root dir:\tphar://wp-cli.phar/vendor/wp-cli/wp-cli\n```\n\n```sh-session\n# Good: Installed via this role, i.e: composer\n$ wp cli info\nWP-CLI root dir:\t/home/web/.composer/vendor/wp-cli/wp-cli\n```\n\n### Is it idempotent or deterministic?\n\nNo.\n\nSpecific exact package versions might help but you will need to manage them manually.\n\n### It looks awesome. Where can I find more goodies like this?\n\n- Articles on [Itineris' blog](https://www.itineris.co.uk/blog/)\n- More projects on [Itineris' GitHub profile](https://github.com/itinerisltd)\n- More plugins on [Itineris](https://profiles.wordpress.org/itinerisltd/#content-plugins) and [TangRufus](https://profiles.wordpress.org/tangrufus/#content-plugins) wp.org profiles\n- Follow [@itineris_ltd](https://twitter.com/itineris_ltd) and [@TangRufus](https://twitter.com/tangrufus) on Twitter\n- Hire [Itineris](https://www.itineris.co.uk/services/) to build your next awesome site\n\n### Where can I give :star::star::star::star::star: reviews?\n\nThanks! Glad you like it. It's important to let my boss knows somebody is using this project. Since this is not hosted on wordpress.org, please consider:\n\n- tweet something good with mentioning [@itineris_ltd](https://twitter.com/itineris_ltd) and [@TangRufus](https://twitter.com/tangrufus)\n- :star: star this [Github repo](https://github.com/ItinerisLtd/trellis_install_wp_cli_via_composer)\n- :eyes: [watch](https://github.com/ItinerisLtd/trellis_install_wp_cli_via_composer/subscription) this Github repo\n- write blog posts\n- submit [pull requests](https://github.com/ItinerisLtd/trellis_install_wp_cli_via_composer)\n- [hire Itineris](https://www.itineris.co.uk/services/)\n\n## Testing\n\n```bash\nansible-playbook -i 'localhost,' --syntax-check tests/test.yml\n```\n\n## Feedback\n\n**Please provide feedback!** We want to make this library useful in as many projects as possible.\nPlease submit an [issue](https://github.com/ItinerisLtd/trellis_install_wp_cli_via_composer/issues/new) and point out what you do and don't like, or fork the project and make suggestions.\n**No issue is too small.**\n\n## Security\n\nIf you discover any security related issues, please email [dev@itineris.co.uk](mailto:dev@itineris.co.uk) instead of using the issue tracker.\n\n## Credits\n\n[trellis_install_wp_cli_via_composer](https://github.com/ItinerisLtd/trellis_install_wp_cli_via_composer) is a [Itineris Limited](https://www.itineris.co.uk/) project created by [Tang Rufus](https://typist.tech).\n\nFull list of contributors can be found [here](https://github.com/ItinerisLtd/trellis_install_wp_cli_via_composer/graphs/contributors).\n\n## License\n\n[trellis_install_wp_cli_via_composer](https://github.com/ItinerisLtd/trellis_install_wp_cli_via_composer) is released under the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitinerisltd%2Ftrellis_install_wp_cli_via_composer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fitinerisltd%2Ftrellis_install_wp_cli_via_composer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitinerisltd%2Ftrellis_install_wp_cli_via_composer/lists"}