Our How-To-Learns are concise articles with information about how to learn various tools, techniques, skills, etc. These articles won’t teach you directly, instead they’ll make it easier to find authoritative, up-to-date, and relevant information to master the topic.
For the past several years…. ok, maybe a decade… I’ve been happily growing my personal, private collection of reusable PHP classes, plugins, libraries, modules, themes and even frameworks and a CMS. All coded by me, from scratch. Imagine my excitement – and more than a little embarrassment – when I discovered Packagist and the amazing tool of Composer which pulls the libraries published on Packagist into your project with a snap. It’s beautiful. And it’s become the industry standard along with the autoloading library it comes with. How can we learn Composer?
What Is Composer?
Composer is a project dependency management tool. It allows you to easily download and install 3rd party libraries into your PHP projects, manage their updates, autoload their classes, and specify versions. It’s a big step up from downloading it yourself and finding a place to put it in your project, then remembering to update it.
How Do I learn Composer?
- From the source: Composer’s official documentation is a good starting point, although you might want to check out a few other resources to learn what it does and why you should use it, before you jump into the docs: https://getcomposer.org/doc/00-intro.md.
- LaraCasts: There are several videos about Composer on Laracasts, many are free. Including this one that is excellent even though the video is tagged as archived: https://laracasts.com/series/laravel-5-alpha-from-scratch/episodes/1.
- Code Mentor‘s article is one that I read early-on and it gave me a good jump-start: https://www.codementor.io/jadjoubran/php-tutorial-getting-started-with-composer-8sbn6fb6t
- SitePoint has a recent article giving a great, in-depth overview of composer: https://www.sitepoint.com/re-introducing-composer/.
The best way to cement your Composer skills is to actually use it. Such is the case for most tools, but here are some tasks to try out:
- Install Composer. Get it working it.
- Create an empty project folder and try using Composer to bring a few libraries into it. Monolog is a nice one to play with.
- Check out how the included libraries are organized in your project folder. Note how you will have to add the vendor directory and composer.lock to your Git/repo ignore list.
- Try changing the requested versions for some of the packages, delete them and have Composer bring them back.
- Do you have a nice library you could share? Learn how to publish one of your own packages on Packagist.
Getting Help With Composer
Unfortunately, neither the Composer or Packagist websites have forums at this time. So the best bets for getting help are places where you’ll find general PHP help, like your favourite web development or PHP forum, Stack Overflow’s Compser tag, the PHP Reddit, or fire out a question on Twitter.