ItinerisLtd.trellis_install_wp_cli_via_composer
Installing WP-CLI via Composer on Trellis
This guide will help you install WP-CLI using Composer on Trellis servers.
Table of Contents
Goal
The Problem
Since WP-CLI version 2.0.0, some old issues with dependencies have been resolved. However, some packages are still bundled together, causing conflicts. For example, WP-CLI 2.4.0 carries an old version of symfony/process
, which can cause issues if you need a newer version for other commands.
The Solution
To avoid conflicts, you can install WP-CLI using Composer. This way, you can manage the package versions easily and avoid problems related to older dependencies.
Role Variables
Here are the default configurations:
# Packages to remove before installing WP-CLI
wp_cli_composer_global_remove_packages:
- wp-cli/wp-cli-bundle
- psy/psysh
# Packages to install
wp_cli_composer_global_require_packages:
- "wp-cli/wp-cli:2.4.0"
- "wp-cli/package-command:^2"
- "psy/psysh:^0.9.12"
# WP-CLI packages to install
wp_cli_packages:
- "typisttech/image-optimize-command:@stable"
- "[email protected]:Yoast/wp-cli-faker.git"
# Location for WP-CLI
wp_cli_bin_path: /usr/bin/wp
# Path for WP-CLI bash completion
wp_cli_completion_path: /etc/bash_completion.d/wp-completion.bash
Requirements
- Trellis version 1.3.0 or later
- Ansible version 2.7.0 or later
- Python version 3.7.6 or later
Installation Steps
Add the plugin to your
galaxy.yml
file:# galaxy.yml + - src: itinerisltd.trellis_install_wp_cli_via_composer + version: XXX.YYY.ZZZ # Check for the latest version!
Replace the existing
wp-cli
role:# server.yml - - { role: wp-cli, tags: [wp-cli] } + - { role: itinerisltd.trellis_install_wp_cli_via_composer, tags: [wp-cli] }
Install the roles:
trellis galaxy install
Re-provision your server:
trellis provision production
FAQ
How to install only specific commands instead of the whole WP-CLI bundle?
You can selectively install the command packages to keep your servers lightweight. Just edit the role variables as needed.
What to do if Composer can’t install due to conflicting versions?
Check your current Composer packages and adjust the versions in the role variables as necessary.
How to verify WP-CLI installation via Composer?
Run this command and check the output:
$ wp cli info
If it shows a path in the Composer vendor directory, it's installed via Composer.
Testing
You can check the syntax of your setup with this command:
ansible-playbook -i 'localhost,' --syntax-check tests/test.yml
Feedback
We welcome your feedback! If you have suggestions or find issues, please submit an issue on GitHub.
Security
If you discover any security issues, please email [email protected] instead of using the issue tracker.
Credits
This project is a part of Itineris Limited and was created by Tang Rufus.
License
This project is released under the MIT License.
Install WP-CLI via composer on Trellis servers
ansible-galaxy install ItinerisLtd.trellis_install_wp_cli_via_composer