Composer on AMIMOTO AMI
Launching AMIMOTO AMI from the AWS Marketplace takes about one minute. Once you’re up and running customize this server however you’d like, including the installation of a dependency managers like Composer. Our AMIs are built using Amazon Linux the supported and maintained Linux image provided by Amazon Web Services. These instructions work for AMIMOTO AMIs but may not work for others Linux distros.
A Complete Copy and Paste Command
cd ~ && \ sudo curl -sS https://getcomposer.org/installer | sudo php && \ sudo mv composer.phar /usr/local/bin/composer && \ sudo ln -s /usr/local/bin/composer /usr/bin/composer
The Same but Step by Step
$ cd ~ $ sudo curl -sS https://getcomposer.org/installer | sudo php $ sudo mv composer.phar /usr/local/bin/composer $ sudo ln -s /usr/local/bin/composer /usr/bin/composer
What is Composer?
Composer is a package manager for PHP. It gives developers the ability to declare dependencies and handle their installation, removal, versioning and more through the Composer CLI or config files.
If you are not familiar with using Composer or dependency managers this may seem confusing or even unnecessary and I get that. Most WordPress developer or users handle plugin management directly through the plugin directory through wordpress.org or directly by downloading and uploading premium plugins not available there. However, if you are working with other developers or handling any project you would like to scale, Composer may be something yo consider adding to your project.
Using Composer with WordPress
The most common dependency for WordPres are plugins. Setting up a new project with commonly used plugins or keeping them set at a specific version can be handled with Composer. With just a few commands and a simple Composer config file you can install, uninstall, upgrade, and more. You’re probably thinking this sounds like WP-CLI and yes, there is some overlap. The major difference though is using Composer you can keep those settings as code and share with other developers. If you use any VCS like Git to track changes while developing you can set a few updates, commit them and any dev on the project can also be running the same plugins and versions.
While Composer is a PHP package manager, it wasn’t built for WordPress. To help wth this there are projects that make it more WordPress dev friendly like, WordPress Packagist (WPackagist). This is a mirror of the WordPress Plugin Directory and allows users to source from that directly. For custom plugins or premium ones not listed in the directory you can also define private or public Git repos.
Composer settings are maintained with the composer.json file, WPackagist has a great example on their site. It includes all the basic project settings and dependencies needed for your project.
WordPress Projects Already Using Composer
If you want to give it a try but you’re not sure where to get started try one of these projects.
Apollo by J2 Design
Apollo uses composer to manage WordPress and Plugins. With Apollo only the project config is tracked and maintained so everything is installed on any server with Composer installed by running one command. It’s also a complete theme framework boilerplate which includes Gulp, Bourbon, and SCSS to get your project started.
Sage by Roots
Apollo is a fork of Sage, a theme boilerplate built by the Roots.io team. Sage also uses composer to manage dependences like WordPress and plugins.