Composer is a command-line tool that interacts with your project via custom files. To use composer, you need a command-line and a code editor.
- [Instructor] Composer gives you PHP dependency management at project level. That means each project has its own Composer configuration, and you can use Composer to manage different dependencies in as many projects as you like. In this chapter, we'll look at both how Composer works, and how to use it in a project, all at the same time. But first, some housekeeping. Composer works the same on Windows and Mac, so from here on out, I'll be using Windows for my demos, but you can follow along on a Mac if that's your preferred platform. As you can see, I'm using Visual Studio Code as my editor.
You can get Visual Studio Code for free for both Windows and Mac, or you can follow along with any other code editor, it does not matter. In Windows, you use Command Prompt as the command line. To open Command Prompt, hit the Start button, then type in cmd and hit Return. This opens Command Prompt and you're landed on your own user area, which is typically C:\Users\ your login. On a Mac, we use Terminal as the command line. To open Terminal, hold down Command+Space.
This opens Finder, then type in Terminal and hit Return, and you are inside Terminal. Windows now supports bash script, which is Linux scripting. That's the same language we use inside Terminal on a Mac, so the commands I use here on Windows will also work on your Mac. Whatever you build with Composer will be a PHP application, and to run local PHP applications on your computer, you need some sort of virtual web server environment. On my computer, I've set up at virtual host pointed at the directory that holds my current project and created the virtual URL imageabstractor.dev.
To gain access to the site, I then have to first start WampServer, then go to the correct URL in my browser. You can do the same with other AMP Stacks, including MAMP PRO on Mac. The exact setup of this environment falls outside the scope of this course, but we have other courses in the library that cover how to do this in detail. To get a handle on how Composer works, I put together a tiny demo project that uses two Composer packages as dependencies. Right now, it's just a standard HTML/CSS combo, so if you go to the exercise files for this movie, you'll find the starting point for the project that looks much like this.
There's currently no PHP, no dependencies, nothing fancy. It's just a very basic HTML page. And by the end, we'll add in dependencies, we'll add in some PHP, and we'll get everything to work properly. You can use this demo project from the exercise files to follow along, or you can use your own project and pick relevant Composer packages yourself. It's entirely up to you, and it doesn't really matter which option you choose. This course is not about how to use particular Composer packages, it's about how to use Composer itself and then bring in the packages you need.
So follow along with my files or follow along with your own project, and you'll learn the same stuff.
- Running PHP
- Installing Composer
- Finding packages
- Using packages in your code
- Using Composer with version control
- Updating packages