There is no doubt that Composer is a really cool dependency manager for PHP, sort of like NuGet for ASP.net, npm for Node.js and gems for Ruby. It makes the deployment process of libraries that much easier.
Composer is basically a PHP script that you provide with a json file with the your dependencies, and run with
In this post, I’ll take you quickly on what you need to do in order to deploy your PHP website using Git, and setup the deployment process to execute the above command upon each commit. And we will do this on a Windows Azure Website.
Installing Composer locally
I’m going to assume you already have Git tools installed, so I’ll use Git Bash in order to perform the next commands
Just doing the above will install composer into the “Projects” directory
Confirm Composer in installed by running the below
You should get an output like this
Using Composer for something useful. Installing Symfony2
Now to demonstrate the power and versatility of Composer, let’s install the Symfony2 PHP framework using Composer by executing this command in our Projects (usually this is our webserver’s htdocs, wwwroot or similar) which will create a new Symfony project in the “MySymfonyProject” folder using Symfony version 2.4.1
Composer will crunch away for a while downloading Symfony and its dependencies
Once it is done you will be left with the below directory structure for your project
Let’s take a look at the composer.json file
Note the "require” part, this is where Symfony specified which packages it needs and hence Composer downloaded them into the “vendor” directory:
Now copy the composer.phar file into your project directory for easier access. At any point if we want to add more packages and update old ones, you add them to the composer.json file and then run
To be continued..
In this part we covered how to create a Composer enabled PHP web application. In part 2 of this post, I’ll cover how to create a Windows Azure Website, set-up Git deployment and modify the post deployment actions to run the composer install command after each commit. What benefit would that give us? You’d have to read part 2 in order to find out!