Composer is one of the best thing we have in PHP development eco system. Before composer there was no standard way of manage dependencies in PHP project. Nowadays composer is a must have skill in PHP developer’s resume. Some project like Laravel framework, composer is required. If you are newbie in PHP community or just started with Laravel framework, don’t worry! In this series of article, I’ll go through all you need to know about composer to start using.
What is Composer?
Composer is a package manager tool for PHP. Other programming language have their own package manager tools like Ruby has ‘bundler’ and Node.js has ‘npm’, now we have composer. Using composer, we can install new packages as well as manage our project dependencies. It also has some other cool features like autoload capacity what allows auto load libraries/classes to make the functionalities available to use all over the application. Ok! Let’s start.
Get Composer Globally:
Install composer is really easy and straightforward. Make sure you have installed latest version of PHP on your local machine. Composer required PHP 5.3.2+. There are some other dependencies but don’t worry about this right now. The installer will check and notify you if anything you need to do.
TIPS: Run this command
php -v on your terminal to know the current PHP version you have installed.
TIPS: Before start move the cursor to the root by running this command
Run this in your terminal to get the latest version of Composer:
php composer-setup.php --install-dir=bin --filename=composer
NOTE: Don’t break the command. Just copy and paste as it is.
NOTE: For windows download composer from here and install manually.
WARNING: This code may change with new version of the installer. If not work, please get the latest installer code from here.
This installer script will simply check some settings in php.ini, it will warn you if they set incorrectly. Then download the latest composer.phar in the current directory. The workflow is:
- Download the installer to the current directory
- Verify the installer SHA-384 which you can also cross-check here
- Run the installer
- Remove the installer
This will install composer locally. Run this command to check.
To make composer available globally we need to move the composer.phar to the bin directory.
mv composer.phar /usr/local/bin/composer
If this command failed due to permissions. Try this:
sudo mv composer.phar /usr/local/bin/composer
NOTE: You may need to enter password to run this command.
That’s it. Now test it again by simply run composer anywhere in the system.
Composer is ready use in any project. Ok!
Lets digging into the composer little farther with my next article Manage Project Dependencies Using Composer.