Local Installation:
Download composer.phar
and place it in your project directory.
Global Installation:
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
chmod +x /usr/local/bin/composer
A comprehensive cheat sheet for Composer, the dependency manager for PHP. Covers installation, dependency management, autoloading, and common commands with examples.
Local Installation: Download Global Installation:
|
Verify Installation:
|
Ensure that PHP is installed and accessible from your command line. |
|
Initializes a new composer project in the current directory. |
|
Installs the project’s dependencies from the |
|
Updates the project’s dependencies to the latest versions specified in |
|
Adds a new dependency to the |
|
Removes a dependency from the |
|
Regenerates the autoloader files. |
|
|
Specific version. |
|
Minimum version, allows later versions. |
|
Maximum version, allows earlier versions. |
|
Equivalent to |
|
Equivalent to |
|
Any version. Not recommended for production. |
|
Install the latest code from the |
|
Always commit your |
If you want to update only single package use |
If Composer encounters conflicts, it will provide error messages suggesting how to resolve them. This often involves relaxing version constraints in your |
Use |
Consider using the |
PSR-4 is the recommended autoloading standard. Specify the namespace to directory mapping in the
This maps the |
After modifying the |
Classmap autoloading scans specified directories for PHP classes and builds a map.
Run |
Files autoloading includes specified PHP files.
Run |
Use the
This generates a single |
Define custom scripts in the
Run scripts using
|
Configure custom repositories in the
|
Supported repository types include |
Specify platform requirements in the
|
This is useful for ensuring compatibility on different environments. |
Composer plugins extend Composer’s functionality. Install plugins like any other dependency. Ensure
|