Laravel 4 and <code>composer.lock</code>
Posted - ⚓The stable release of Laravel 4 is soon upon us. If you use git to work with Laravel like I do then there is a possible improvement to how you deploy your code.
The default .gitignore
file includes the composer.lock
file. If you want to know how composer works Dayle Rees wrote an excellent primer. Essentially a project will have composer.json
file which details the dependencies. The true power of composer lies in the cascading nature of the dependency resolution, i.e. a dependency can have its own dependencies and composer will sort all this out for you.
When composer goes about resolving these dependencies, initiated through composer update
it retrieves the libraries/projects, normally from Github, and saves them to the ./vendor
folder. Composer then creates a new file called composer.lock
, or updates said file if it already exists. This file is a list of the exact versions of the dependencies installed.
Once you are sure all your code works as expected, including that the dependencies work as they should you commit your code and deploy it to the server. Our composer.lock
file allows us to tie our project to dependencies we know work, when we run composer install
then composer will read the contents of the composer.lock
file and install exactly those dependencies down to the exact version. This way we can safeguard against unwanted surprises when deploying our code in production. You have to be careful when you live on the bleeding-edge of code.
Unfortunately Laravel doesn’t promote this practice. Maybe I'll open an issue about it.