
What is Composer?
Composer is a tool for dependency management for PHP that help us to manage the packages. Composer is a package manager for PHP β it helps you install, update, and use code written by others in your own PHP project.
π οΈ What Does Composer Do?
- β Installs packages (libraries/tools your project needs)
- π¦ Tracks dependencies (it knows which version of which library your app uses)
- π Updates libraries when new versions are available
- π Creates autoloaders (makes it easy to include and use classes automatically)
π Simple Example
Say you’re building a PHP app and want to send emails.
Instead of writing everything from scratch, you can use a package like PHPMailer.
With Composer, you just run:
composer require phpmailer/phpmailer
β Step 1: Check if Composer is Installed
π Open your terminal or command prompt and run:
composer -V
or
composer --version
β If installed, youβll see something like:
Composer version 2.7.2 2024-05-15 16:45:23
β If not installed, youβll get something like:
'composer' is not recognized as an internal or external command...
πΎ Step 2: How to Install Composer (if not installed)
1. Go to https://getcomposer.org/
2. Download the Composer-Setup.exe
3. Run it and follow the instructions (make sure PHP is installed)
Common Composer Commands
Hereβs a list of useful Composer CLI commands with short descriptions:
| Command | Description |
|---|---|
about | Shows a short information about Composer |
archive | Creates an archive of this composer package |
audit | Checks for security vulnerability advisories for installed packages |
browse [home] | Opens the package’s repository URL or homepage in your browser |
bump | Increases the lower limit of your composer.json requirements to the currently installed versions |
check-platform-reqs | Check that platform requirements are satisfied |
clear-cache [clearcache|cc] | Clears Composer’s internal package cache |
completion | Dump the shell completion script |
config | Sets config options |
create-project | Creates new project from a package into given directory |
depends [why] | Shows which packages cause the given package to be installed |
diagnose | Diagnoses the system to identify common errors |
dump-autoload [dumpautoload] | Dumps the autoloader |
exec | Executes a vendored binary/script |
fund | Discover how to help fund the maintenance of your dependencies |
global | Allows running commands in the global composer dir ($COMPOSER_HOME) |
help | Display help for a command |
init | Creates a basic composer.json file in current directory |
install [i] | Installs the project dependencies from the composer.lock file if present, or falls back on the composer.json |
licenses | Shows information about licenses of dependencies |
list | List commands |
outdated | Shows a list of installed packages that have updates available |
prohibits [why-not] | Shows which packages prevent the given package from being installed |
reinstall | Uninstalls and reinstalls the given package names |
remove [rm|uninstall] | Removes a package from the require or require-dev |
require [r] | Adds required packages to your composer.json and installs them |
run-script [run] | Runs the scripts defined in composer.json |
search | Searches for packages |
self-update [selfupdate] | Updates composer.phar to the latest version |
show [info] | Shows information about packages |
status | Shows a list of locally modified packages |
suggests | Shows package suggestions |
update [u|upgrade] | Updates your dependencies to the latest version according to composer.json |
validate | Validates a composer.json and composer.lock |
LEAVE A COMMENT
Our Services
Discover our range of professional services designed to meet your needs. We provide expert solutions with precision and excellence to help you achieve your goals.
Comments (0)
No comments yet. Be the first to comment!