### Check Composer Setup Source: https://getcomposer.org/doc/articles/troubleshooting.md Run this command to verify your Composer installation and environment are set up correctly. ```bash curl -sS https://getcomposer.org/installer | php -- --check ``` -------------------------------- ### Get Help for a Composer Command Source: https://getcomposer.org/doc/03-cli.md Use the help command to get more information about a specific Composer command, such as 'install'. ```bash php composer.phar help install ``` -------------------------------- ### Install Project Dependencies Source: https://getcomposer.org/doc/03-cli.md The `install` command reads `composer.json`, resolves dependencies, and installs them into the `vendor` directory. If a `composer.lock` file exists, it uses the exact versions specified there. ```bash php composer.phar install ``` -------------------------------- ### Complete Composer Plugin Example with Event Subscription Source: https://getcomposer.org/doc/articles/plugins.md A full example of a Composer plugin implementing PluginInterface and EventSubscriberInterface, including event registration for pre-file download. ```php composer = $composer; $this->io = $io; } public function deactivate(Composer $composer, IOInterface $io) { } public function uninstall(Composer $composer, IOInterface $io) { } public static function getSubscribedEvents() { return [ PluginEvents::PRE_FILE_DOWNLOAD => [ ['onPreFileDownload', 0] ], ]; } public function onPreFileDownload(PreFileDownloadEvent $event) { $protocol = parse_url($event->getProcessedUrl(), PHP_URL_SCHEME); if ($protocol === 's3') { // ... } } } ``` -------------------------------- ### Install Project Dependencies with Composer Source: https://getcomposer.org/doc/01-basic-usage.md Run this command to initially install all defined dependencies for your project. It resolves dependencies, writes them to `composer.lock`, and downloads them into the `vendor` directory. ```bash php composer.phar update ``` -------------------------------- ### Notify-Batch POST Request Body Example Source: https://getcomposer.org/doc/05-repositories.md Illustrates the JSON payload sent to the 'notify-batch' URL when a package is installed, detailing the downloaded package and its version. ```json { "downloads": [ {"name": "monolog/monolog", "version": "1.2.1.0"} ] } ``` -------------------------------- ### Install from Source Source: https://getcomposer.org/doc/03-cli.md Use this option to install a package from its source (e.g., a Git repository) instead of a distribution archive. This is useful for making local modifications to dependencies. ```bash php composer.phar install --prefer-source ``` -------------------------------- ### Install with Auto Source Preference Source: https://getcomposer.org/doc/03-cli.md Installs from source automatically for development versions of packages, maintaining legacy behavior. ```bash php composer.phar install --prefer-install=auto ``` -------------------------------- ### Programmatic Composer Installation with Shell Script Source: https://getcomposer.org/doc/faqs/how-to-install-composer-programmatically.md This script downloads the Composer installer, verifies its checksum against a remote signature, and then executes it quietly. It cleans up the installer script afterward. Use this for automated installations where checksum verification is crucial. ```shell #!/bin/sh EXPECTED_CHECKSUM="$(php -r 'copy("https://composer.github.io/installer.sig", "php://stdout");')" php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" ACTUAL_CHECKSUM="$(php -r "echo hash_file('sha384', 'composer-setup.php');")" if [ "$EXPECTED_CHECKSUM" != "$ACTUAL_CHECKSUM" ] then >&2 echo 'ERROR: Invalid installer checksum' rm composer-setup.php exit 1 fi php composer-setup.php --quiet RESULT=$? rm composer-setup.php exit $RESULT ``` -------------------------------- ### Example composer.json for a phpDocumentor template package Source: https://getcomposer.org/doc/articles/custom-installers.md Defines a package of type 'phpdocumentor-template' and requires the installer plugin. Ensure the installer plugin is a dependency to guarantee its presence during installation. ```json { "name": "phpdocumentor/template-responsive", "type": "phpdocumentor-template", "require": { "phpdocumentor/template-installer-plugin": "*" } } ``` -------------------------------- ### Configure Preferred Installation Methods Source: https://getcomposer.org/doc/06-config.md Sets the preferred installation method for packages, allowing granular control per package or pattern. Supports 'source', 'dist', and 'auto'. ```json { "config": { "preferred-install": { "my-organization/stable-package": "dist", "my-organization/*": "source", "partner-organization/*": "auto", "*": "dist" } } } ``` -------------------------------- ### Initialize a New Composer Project Source: https://getcomposer.org/doc/03-cli.md The `init` command interactively guides you through creating a `composer.json` file for a new project, using smart defaults for fields. ```bash php composer.phar init ``` -------------------------------- ### Composer.json with Vendor Binaries Source: https://getcomposer.org/doc/articles/vendor-binaries.md Example of a package's composer.json defining a vendor binary. ```json { "name": "my-vendor/project-a", "bin": ["bin/project-a-bin"] } ``` -------------------------------- ### Troubleshoot Vendor Installation Source: https://getcomposer.org/doc/articles/troubleshooting.md When facing issues, remove the existing vendor directory and update dependencies from scratch to ensure a clean installation. ```bash rm -rf vendor && composer update -v ``` -------------------------------- ### Install Composer using a Specific GitHub Commit Hash Source: https://getcomposer.org/doc/faqs/how-to-install-composer-programmatically.md This method downloads the installer script directly from a specific commit on GitHub, bypassing the checksum verification of the official installer. It's useful if you need to pin to an exact version of the installer script. ```shell wget https://raw.githubusercontent.com/composer/getcomposer.org/f3108f64b4e1c1ce6eb462b159956461592b3e3e/web/installer -O - -q | php -- --quiet ``` -------------------------------- ### Composer Project Setup Source: https://getcomposer.org/doc/01-basic-usage.md Define project dependencies in `composer.json` using the `require` key. Specify package names and their version constraints. ```json { "require": { "monolog/monolog": "2.0.*" } } ``` -------------------------------- ### Get Installed Packages by Type Source: https://getcomposer.org/doc/07-runtime.md Retrieve a list of installed packages of a specific type, such as plugins. This method is available from Composer 2.1 and requires `composer-runtime-api ^2.1`. ```php \Composer\InstalledVersions::getInstalledPackagesByType('foo-plugin'); ``` -------------------------------- ### Set Global Preferred Install Method Source: https://getcomposer.org/doc/06-config.md Sets the preferred installation method globally for a specific package pattern using the Composer CLI. ```bash composer config --global preferred-install.my-vendor/* source ``` -------------------------------- ### Install Global Package Source: https://getcomposer.org/doc/03-cli.md Installs a package globally, making its binaries available in your system's PATH. Ensure your global vendor binaries directory is configured and in your PATH. ```bash php composer.phar global require friendsofphp/php-cs-fixer ``` -------------------------------- ### Install Composer Locally on Linux/Unix/macOS Source: https://getcomposer.org/doc/00-intro.md Installs Composer as a PHAR archive in the current project directory. This is useful for project-specific installations. ```bash php composer-setup.php --install-dir=bin --filename=composer php bin/composer ``` -------------------------------- ### Display Composer Help Source: https://getcomposer.org/doc/03-cli.md To get help from the command-line, call `composer` or `composer list` to see the complete list of commands. Use `--help` with any command for more specific information. ```bash php composer.phar list php composer.phar --help php composer.phar install --help ``` -------------------------------- ### Custom Template Installer Implementation Source: https://getcomposer.org/doc/articles/custom-installers.md Extends `LibraryInstaller` to define a custom installation path for phpDocumentor templates. It checks if the package name starts with the expected prefix and returns a path within the 'data/templates/' directory. ```php getPrettyName(), 0, 23); if ('phpdocumentor/template-' !== $prefix) { throw new \InvalidArgumentException( 'Unable to install template, phpdocumentor templates ' .'should always start their package name with ' .'"phpdocumentor/template-"' ); } return 'data/templates/'.substr($package->getPrettyName(), 23); } /** * @inheritDoc */ public function supports($packageType) { return 'phpdocumentor-template' === $packageType; } } ``` -------------------------------- ### Composer Version Output Source: https://getcomposer.org/doc/00-intro.md Example output showing the Composer version after verification. ```text Composer version 2.4.0 2022-08-16 16:10:48 ``` -------------------------------- ### Get the installation path of a package Source: https://getcomposer.org/doc/07-runtime.md Use `getInstallPath` to retrieve the absolute installation path of a package. This method returns `null` if the package is provided, replaced, or is a metapackage. The returned path may contain `../` or symlinks and might require `realpath()` for exact equivalence. ```php // returns an absolute path to the package installation location if vendor/package is installed, // or null if it is provided/replaced, or the package is a metapackage // or throws OutOfBoundsException if the package is not installed at all \Composer\InstalledVersions::getInstallPath('vendor/package'); ``` -------------------------------- ### Plugin class to register a custom installer Source: https://getcomposer.org/doc/articles/custom-installers.md Implements the PluginInterface and registers a custom installer instance in the activate method. This class must be autoloadable and match the 'extra.class' definition in the composer.json. ```php getInstallationManager()->addInstaller($installer); } } ``` -------------------------------- ### Run Composer Install with Docker Source: https://getcomposer.org/doc/00-intro.md Executes Composer's install command within a Docker container, mounting the current directory for project access. ```bash docker pull composer/composer docker run --rm -it -v "$(pwd):/app" composer/composer install ``` -------------------------------- ### Composer Version Constraint Examples Source: https://getcomposer.org/doc/articles/versions.md Illustrates various ways to specify package versions in `composer.json`, from exact matches to ranges and semantic versioning operators. ```json "require": { "vendor/package": "1.3.2", // exactly 1.3.2 // >, <, >=, <= | specify upper / lower bounds "vendor/package": ">=1.3.2", // anything above or equal to 1.3.2 "vendor/package": "<1.3.2", // anything below 1.3.2 // * | wildcard "vendor/package": "1.3.*", // >=1.3.0 <1.4.0 // ~ | allows last digit specified to go up "vendor/package": "~1.3.2", // >=1.3.2 <1.4.0 "vendor/package": "~1.3", // >=1.3.0 <2.0.0 // ^ | doesn't allow breaking changes (major version fixed - following semver) "vendor/package": "^1.3.2", // >=1.3.2 <2.0.0 "vendor/package": "^0.3.2" // >=0.3.2 <0.4.0 // except if major version is 0 } ``` -------------------------------- ### Prefer source installation Source: https://getcomposer.org/doc/03-cli.md Use --prefer-install=source to instruct Composer to download packages from their source (e.g., git clone) if available, which is useful for making direct bug fixes to dependencies. ```bash php composer.phar require --prefer-source vendor/package ``` -------------------------------- ### Create New Project from Package Source: https://getcomposer.org/doc/03-cli.md Use this command to create a new project from an existing package. This is useful for deploying application packages, starting development on patches, or bootstrapping a project for multiple developers. The command will create the specified directory if it does not exist. ```bash php composer.phar create-project composer/hello-world my-project ``` -------------------------------- ### Discover package funding links Source: https://getcomposer.org/doc/03-cli.md Lists all funding links from installed dependencies to help discover how to support package maintenance. Use --format=json for machine-readable output. ```bash php composer.phar fund ``` ```bash php composer.phar fund --format=json ``` -------------------------------- ### List installed packages with updates available Source: https://getcomposer.org/doc/03-cli.md The `outdated` command lists installed packages that have newer versions available. It is an alias for `composer show -lo`. ```bash composer outdated ``` -------------------------------- ### Install Dependencies from composer.lock Source: https://getcomposer.org/doc/01-basic-usage.md Use this command when a `composer.lock` file is present to ensure consistent dependency versions across all environments. It installs dependencies based on the exact versions specified in the lock file. ```bash php composer.phar install ``` -------------------------------- ### Install Bash Completions for Composer Source: https://getcomposer.org/doc/03-cli.md Installs bash completions for Composer. The generated file can be sourced for immediate use or moved to a system directory for automatic loading in new terminal sessions. ```bash php composer.phar completion bash > completion.bash source completion.bash # To make it permanent, move and rename the file: # mv completion.bash /etc/bash_completion.d/composer ``` -------------------------------- ### Validate Composer Files Source: https://getcomposer.org/doc/articles/resolving-merge-conflicts.md Run these commands to ensure your composer.json and composer.lock files are valid after merging. The install command with --dry-run simulates installation without making changes. ```bash php composer.phar validate php composer.phar install [--dry-run] ``` -------------------------------- ### Composer.json with Dependencies Source: https://getcomposer.org/doc/articles/vendor-binaries.md Example of a project's composer.json requiring another package that has vendor binaries defined. ```json { "name": "my-vendor/project-b", "require": { "my-vendor/project-a": "*" } } ``` -------------------------------- ### Specify Exact Package Version Source: https://getcomposer.org/doc/articles/versions.md Use this to install a specific version of a package. The solver will fail if other dependencies require a different version. ```plaintext 1.0.2 ``` -------------------------------- ### Minimal Package Definition Source: https://getcomposer.org/doc/05-repositories.md A basic example of a package definition within a composer repository, including name, version, and distribution details. ```json { "name": "smarty/smarty", "version": "3.1.7", "dist": { "url": "https://www.smarty.net/files/Smarty-3.1.7.zip", "type": "zip" } } ``` -------------------------------- ### Package Suggestions Configuration Source: https://getcomposer.org/doc/04-schema.md Defines packages that can enhance or work well with the current package. These are informational and displayed after installation. ```json { "suggest": { "monolog/monolog": "Allows more advanced logging of the application flow", "ext-xml": "Needed to support XML format in class Foo" } } ``` -------------------------------- ### Get the installed version of a package Source: https://getcomposer.org/doc/07-runtime.md Retrieve the normalized or pretty version string of an installed package using `Composer\InstalledVersions::getVersion()` or `Composer\InstalledVersions::getPrettyVersion()`. `getReference()` can be used to get the package's dist or source reference. ```APIDOC ## Get the installed version of a package ### Description Retrieves the version information for an installed package. ### Method `Composer\InstalledVersions::getVersion(string $package): ?string` `Composer\InstalledVersions::getPrettyVersion(string $package): ?string` `Composer\InstalledVersions::getReference(string $package): ?string` ### Parameters #### Path Parameters - **package** (string) - Required - The name of the package. ### Request Example ```php // Returns a normalized version (e.g. 1.2.3.0) \Composer\InstalledVersions::getVersion('vendor/package'); // Returns the original version (e.g. v1.2.3) \Composer\InstalledVersions::getPrettyVersion('vendor/package'); // Returns the package dist or source reference (e.g. a git commit hash) \Composer\InstalledVersions::getReference('vendor/package'); ``` ``` -------------------------------- ### List all available packages Source: https://getcomposer.org/doc/03-cli.md Use the `show` command without arguments to list all packages available in your repositories. ```bash php composer.phar show ``` -------------------------------- ### Get the normalized version of an installed package Source: https://getcomposer.org/doc/07-runtime.md Use `getVersion` to retrieve the normalized version string of an installed package. This method returns `null` if the package is provided or replaced by another, and throws `OutOfBoundsException` if the package is not installed at all. ```php // returns a normalized version (e.g. 1.2.3.0) if vendor/package is installed, // or null if it is provided/replaced, // or throws OutOfBoundsException if the package is not installed at all \Composer\InstalledVersions::getVersion('vendor/package'); ``` -------------------------------- ### Ignore all platform requirements Source: https://getcomposer.org/doc/03-cli.md The --ignore-platform-reqs flag forces installation even if the local machine does not meet platform requirements like PHP version or extensions. ```bash php composer.phar require --ignore-platform-reqs vendor/package ``` -------------------------------- ### List Repositories Source: https://getcomposer.org/doc/03-cli.md Display all configured repositories in your composer.json. ```bash php composer.phar repo list ``` -------------------------------- ### Per-Package Metadata Filter Entry Source: https://getcomposer.org/doc/05-repositories.md Example of filter data included within a package's per-package metadata file. ```json { "packages": { "vendor/package": [{ ... }] }, "filter": { "malware": [ { "constraint": ">=1.0.0,<1.2.0", "url": "https://example.org/filters/123", "reason": "Malware", "id": "PKFE-xxxx-xxxx-xxxx" } ] } } ``` -------------------------------- ### Get the pretty version of an installed package Source: https://getcomposer.org/doc/07-runtime.md Use `getPrettyVersion` to retrieve the original, human-readable version string of an installed package (e.g., 'v1.2.3'). Similar to `getVersion`, it returns `null` for provided/replaced packages and throws `OutOfBoundsException` if the package is not installed. ```php // returns the original version (e.g. v1.2.3) if vendor/package is installed, // or null if it is provided/replaced, // or throws OutOfBoundsException if the package is not installed at all \Composer\InstalledVersions::getPrettyVersion('vendor/package'); ``` -------------------------------- ### Configure HTTP Basic Authentication Source: https://getcomposer.org/doc/articles/authentication-for-private-packages.md Sets up HTTP basic authentication for a specific repository host. Replace 'repo.example.org' with your repository's hostname. ```bash php composer.phar config [--global] http-basic.repo.example.org username password ``` -------------------------------- ### Set Archive Directory Source: https://getcomposer.org/doc/06-config.md Configure the default destination for archives created by the archive command. This example sets the archive directory to a specific path. ```json { "config": { "archive-dir": "/home/user/.composer/repo" } } ``` -------------------------------- ### Get the installation path of a package Source: https://getcomposer.org/doc/07-runtime.md Use `Composer\InstalledVersions::getInstallPath()` to obtain the absolute installation directory of a package. Note that the path may contain `../` or symlinks and might require `realpath()` for certain use cases. ```APIDOC ## Get the installation path of a package ### Description Retrieves the absolute installation path of a package. ### Method `Composer\InstalledVersions::getInstallPath(string $package): ?string` ### Parameters #### Path Parameters - **package** (string) - Required - The name of the package. ### Request Example ```php // Returns an absolute path to the package installation location \Composer\InstalledVersions::getInstallPath('vendor/package'); ``` ``` -------------------------------- ### Browse package repository or homepage Source: https://getcomposer.org/doc/03-cli.md Opens a package's repository URL or homepage in your browser. Use the --homepage flag to open the homepage instead of the repository URL, or --show to only display the URL without opening it. ```bash php composer.phar browse vendor/package ``` ```bash php composer.phar browse --homepage vendor/package ``` ```bash php composer.phar browse --show vendor/package ``` ```bash php composer.phar home vendor/package ``` -------------------------------- ### List package suggestions Source: https://getcomposer.org/doc/03-cli.md Lists all packages suggested by the currently installed set of packages. You can filter by specific packages, group output by package or suggestion, show all dependencies, or list only package names. Use --no-dev to exclude suggestions from dev dependencies. ```bash php composer.phar suggests ``` ```bash php composer.phar suggests vendor/package ``` ```bash php composer.phar suggests --by-suggestion vendor/package ``` ```bash php composer.phar suggests --all ``` ```bash php composer.phar suggests --list ``` ```bash php composer.phar suggests --no-dev ``` -------------------------------- ### Get the reference of an installed package Source: https://getcomposer.org/doc/07-runtime.md Use `getReference` to obtain the package's distribution or source reference, such as a Git commit hash. It returns `null` if the package is provided or replaced, and throws `OutOfBoundsException` if the package is not installed. ```php // returns the package dist or source reference (e.g. a git commit hash) if vendor/package is installed, // or null if it is provided/replaced, // or throws OutOfBoundsException if the package is not installed at all \Composer\InstalledVersions::getReference('vendor/package'); ``` -------------------------------- ### Check Platform Requirements with Lock File Source: https://getcomposer.org/doc/03-cli.md Checks platform requirements solely based on the lock file, ignoring installed packages. This is useful for verifying production server compatibility. ```bash php composer.phar check-platform-reqs --lock ``` -------------------------------- ### Configure Security Advisory Blocking Source: https://getcomposer.org/doc/06-config.md When `policy.advisories.block` is `true` (default), package versions with active security advisories are blocked. Setting it to `false` allows installation of such versions. ```json { "config": { "policy": { "advisories": { "block": false } } } } ``` -------------------------------- ### HTTP Basic Authentication Structure Source: https://getcomposer.org/doc/articles/authentication-for-private-packages.md Example JSON structure for defining HTTP basic authentication credentials in an auth.json file. This includes username and password for a specific host. ```json { "http-basic": { "example.org": { "username": "username", "password": "password" } } } ``` -------------------------------- ### List Network Services on macOS Source: https://getcomposer.org/doc/articles/troubleshooting.md Use the networksetup command to list all available network services on macOS. This is a preliminary step before disabling IPv6 on a specific network device. ```bash networksetup -listallnetworkservices ``` -------------------------------- ### Get Global Bin Directory Source: https://getcomposer.org/doc/03-cli.md Retrieves the absolute path to the directory where globally installed vendor binaries are stored. This is useful for configuring your system's PATH. ```bash php composer.phar global config bin-dir --absolute ``` -------------------------------- ### Download and Verify Composer using GitHub CLI Source: https://getcomposer.org/doc/faqs/how-to-install-composer-programmatically.md This approach uses the GitHub CLI to download a specific release artifact (composer.phar) and then verify its integrity. This is a modern alternative for automated environments that have the gh CLI installed. ```shell gh release --repo composer/composer download --pattern composer.phar ``` ```shell gh attestation verify --repo composer/composer composer.phar ``` -------------------------------- ### Show package details Source: https://getcomposer.org/doc/03-cli.md To view the details of a specific package, provide its name as an argument to the `show` command. ```bash php composer.phar show monolog/monolog ``` -------------------------------- ### List Configuration Values with Sources Source: https://getcomposer.org/doc/articles/troubleshooting.md Use this command to inspect configuration values and determine their origin. ```bash php composer.phar config --list --source ``` -------------------------------- ### Configure Bitbucket OAuth Consumer via Command Line Source: https://getcomposer.org/doc/articles/authentication-for-private-packages.md Set up your Bitbucket OAuth consumer key and secret for private Bitbucket package access. ```bash php composer.phar config [--global] bitbucket-oauth.bitbucket.org consumer-key consumer-secret ``` -------------------------------- ### Configure Inline HTTP Basic Authentication (Command Line) Source: https://getcomposer.org/doc/articles/authentication-for-private-packages.md Use this command to set up inline HTTP basic authentication for a Composer repository directly in the configuration. ```bash php composer.phar config [--global] repositories.unique-name composer https://username:password@repo.example.org ``` -------------------------------- ### Audit Installed Packages Source: https://getcomposer.org/doc/03-cli.md Audit installed packages against defined policies, such as security advisories. This command checks for vulnerabilities, abandoned, or malware packages. ```bash php composer.phar audit ``` -------------------------------- ### Configure GitLab Token Authentication (Command Line) Source: https://getcomposer.org/doc/articles/authentication-for-private-packages.md Set up GitLab token authentication for a specific GitLab instance using the command line. ```bash php composer.phar config [--global] gitlab-token.gitlab.example.org token ``` -------------------------------- ### Verify Composer Installation Source: https://getcomposer.org/doc/00-intro.md Checks the installed Composer version from a new terminal session. This confirms Composer is accessible via the command line. ```bash C:\Users\username>composer -V ``` -------------------------------- ### Reinstall specific packages Source: https://getcomposer.org/doc/03-cli.md Use the reinstall command to uninstall and then reinstall specified packages. This is useful for ensuring a clean installation or changing installation preferences. ```bash php composer.phar reinstall acme/foo acme/bar ``` -------------------------------- ### Configure Bitbucket API Token via Command Line Source: https://getcomposer.org/doc/articles/authentication-for-private-packages.md Use this command to configure your Bitbucket API token for HTTP Basic authentication. ```bash php composer.phar config [--global] http-basic.bitbucket.org your@email.com api-token ``` -------------------------------- ### Configure Forgejo Token Authentication (Command Line) Source: https://getcomposer.org/doc/articles/authentication-for-private-packages.md Configure Forgejo token authentication directly via the command line for a specified Forgejo instance. Replace 'forgejo.example.org' with your instance's hostname. ```bash php composer.phar config [--global] forgejo-token.forgejo.example.org username access-token ``` -------------------------------- ### Disable immediate installation Source: https://getcomposer.org/doc/03-cli.md Use --no-install to prevent Composer from running the install step after updating the composer.lock file, useful when you only want to update the lock file. ```bash php composer.phar require --no-install vendor/package ``` -------------------------------- ### Enable Source Fallback for Package Installation Source: https://getcomposer.org/doc/06-config.md When set to `true`, a failed `dist` install will fall back to a `source` checkout. This option is deprecated and will be removed in Composer 2.11. ```json { "config": { "source-fallback": true } } ``` -------------------------------- ### Configure PSR-0 Autoloading with Fallback Directory Source: https://getcomposer.org/doc/04-schema.md Use an empty namespace prefix to designate a fallback directory for any namespace not explicitly defined. ```json { "autoload": { "psr-0": { "": "src/" } } } ``` -------------------------------- ### Install Composer Globally on Linux/Unix/macOS Source: https://getcomposer.org/doc/00-intro.md Moves the Composer PHAR to a directory in your system's PATH for global access. Requires root permissions or installation in a user-specific directory. ```bash mv composer.phar /usr/local/bin/composer composer ``` -------------------------------- ### Composer JSON for Custom Installer Paths Source: https://getcomposer.org/doc/faqs/how-do-i-install-a-package-to-a-custom-path-for-my-framework.md For package consumers: Use the 'extra.installer-paths' configuration to override default installation locations for specific packages or package types, such as for Drupal multisite. ```json { "extra": { "installer-paths": { "sites/example.com/modules/{$name}": ["vendor/package"], "sites/example.com/themes/{$name}": ["type:drupal-theme"] } } } ``` -------------------------------- ### Configure PSR-0 Autoloading with Multiple Directories Source: https://getcomposer.org/doc/04-schema.md Specify an array of directories for a single namespace prefix to allow searching in multiple locations. ```json { "autoload": { "psr-0": { "Monolog\\": ["src/", "lib/"] } } } ``` -------------------------------- ### Enable Composer Command-Line Completion Source: https://getcomposer.org/doc/03-cli.md To enable command-line completion, run the `composer completion --help` command and follow the provided instructions. ```bash composer completion --help ``` -------------------------------- ### Add Composer Repository by Name Source: https://getcomposer.org/doc/03-cli.md Add a new Composer repository with a specified name and URL. ```bash php composer.phar repo add bar composer https://repo.packagist.com/bar ``` -------------------------------- ### Configure Plugin to Modify Install Path Source: https://getcomposer.org/doc/articles/plugins.md Set `plugin-modifies-install-path` to `true` in the plugin's `composer.json` to activate the plugin early in the installation process, preventing issues with Composer assuming incorrect package locations. ```json { "extra": { "plugin-modifies-install-path": true } } ``` -------------------------------- ### Configure Custom HTTP Headers (Command Line) Source: https://getcomposer.org/doc/articles/authentication-for-private-packages.md Use the command line to configure custom HTTP headers for authentication with private repositories. ```bash php composer.phar config [--global] custom-headers.repo.example.org "API-TOKEN: YOUR-API-TOKEN" "X-CUSTOM-HEADER: Value" ``` -------------------------------- ### Check if a package satisfies a version constraint Source: https://getcomposer.org/doc/07-runtime.md Use `satisfies` to verify if an installed package meets a specified version constraint. This method requires an instance of `Composer\Semver\VersionParser`. It returns true if the package is installed and matches the constraint, or if it's provided or replaced by another package. ```php use Composer\Semver\VersionParser; \Composer\InstalledVersions::satisfies(new VersionParser, 'vendor/package', '2.0.*'); \Composer\InstalledVersions::satisfies(new VersionParser, 'psr/log-implementation', '^1.0'); ``` -------------------------------- ### Get Repository URL Source: https://getcomposer.org/doc/03-cli.md Retrieve the URL of a specific repository. ```bash php composer.phar repo get-url foo ``` -------------------------------- ### Build Satis Repository Source: https://getcomposer.org/doc/articles/handling-private-packages.md Command to build a Satis repository from a configuration file. Use the --no-interaction flag for automated builds, especially with SSH key authentication for private repositories. ```bash php bin/satis build ``` -------------------------------- ### Satis Configuration: Cherry-Pick Packages Source: https://getcomposer.org/doc/articles/handling-private-packages.md Configure Satis to include specific packages and versions from listed VCS repositories. Use the 'require' key to list desired packages with version constraints. ```json { "repositories": [ { "type": "vcs", "url": "https://github.com/mycompany/privaterepo" }, { "type": "vcs", "url": "http://svn.example.org/private/repo" }, { "type": "vcs", "url": "https://github.com/mycompany/privaterepo2" } ], "require": { "company/package": "*", "company/package2": "*", "company/package3": "2.0.0" } } ``` -------------------------------- ### Configure Target Directory for PSR-0 Autoloading Source: https://getcomposer.org/doc/04-schema.md The `target-dir` option specifies the installation directory for packages, primarily to support legacy PSR-0 autoloading. It ensures packages are installed in a location that allows the autoloader to find them correctly, especially when the package root is not at the namespace declaration level. This is deprecated in favor of PSR-4. ```json { "autoload": { "psr-0": { "Symfony\\Component\\Yaml\\": "" } }, "target-dir": "Symfony/Component/Yaml" } ``` -------------------------------- ### Configure GitLab OAuth Authentication (Command Line) Source: https://getcomposer.org/doc/articles/authentication-for-private-packages.md Set up GitLab OAuth authentication for a specific GitLab instance using the command line. ```bash php composer.phar config [--global] gitlab-oauth.gitlab.example.org token ``` -------------------------------- ### Get Current Memory Limit Source: https://getcomposer.org/doc/articles/troubleshooting.md Retrieve the current PHP memory limit setting. ```php php -r "echo ini_get('memory_limit').PHP_EOL;" ``` -------------------------------- ### Configure Abandoned Packages in satis.json Source: https://getcomposer.org/doc/articles/handling-private-packages.md Use this configuration to indicate that packages are abandoned. Set to `true` for truly abandoned packages or a string for a replacement package. ```json { "abandoned": { "company/package": true, "company/package2": "company/newpackage" } } ``` -------------------------------- ### Configure HTTP Bearer Authentication (Command Line) Source: https://getcomposer.org/doc/articles/authentication-for-private-packages.md Set up HTTP Bearer authentication for a Composer repository using the command line. ```bash php composer.phar config [--global] bearer.repo.example.org token ``` -------------------------------- ### Block Abandoned Packages Source: https://getcomposer.org/doc/06-config.md Configure Composer to block the installation of abandoned packages. This setting defaults to false. ```json { "config": { "policy": { "abandoned": { "block": true } } } } ``` -------------------------------- ### Add Repository Before Another Source: https://getcomposer.org/doc/03-cli.md Insert a new repository before an existing one, controlling its priority. ```bash php composer.phar repo add baz vcs https://example.org --before foo ``` -------------------------------- ### Configure PSR-0 Autoloading with Namespaces Source: https://getcomposer.org/doc/04-schema.md Map namespaces to directories for PSR-0 compliant autoloading. Ensure namespace declarations end with `\\` for exact matching. ```json { "autoload": { "psr-0": { "Monolog\\": "src/", "Vendor\\Namespace\\": "src/", "Vendor_Namespace_": "src/" } } } ``` -------------------------------- ### Configure PSR-0 Autoloading for Global Classes Source: https://getcomposer.org/doc/04-schema.md Map a class name directly to an empty path for classes in the global namespace located at the package root. ```json { "autoload": { "psr-0": { "UniqueGlobalClass": "" } } } ``` -------------------------------- ### Disable All Plugins Source: https://getcomposer.org/doc/articles/plugins.md Use the `--no-plugins` option to temporarily disable all installed Composer plugins. This is useful for troubleshooting. ```bash composer --no-plugins ``` -------------------------------- ### Update all dependencies Source: https://getcomposer.org/doc/03-cli.md Use this command to resolve all project dependencies and update the composer.lock file with the exact versions of the installed packages. ```bash php composer.phar update ``` -------------------------------- ### Running Composer Scripts Manually Source: https://getcomposer.org/doc/articles/scripts.md Demonstrates the command-line syntax for manually executing defined Composer scripts. Arguments can be passed to script handlers using '--'. ```bash php composer.phar run-script [--dev] [--no-dev] script ``` ```bash composer run-script post-install-cmd -- --check ``` -------------------------------- ### Enable Swap Space on Linux Source: https://getcomposer.org/doc/articles/troubleshooting.md Commands to create and enable a swap file if memory is insufficient. This can resolve 'proc_open(): fork failed' errors. ```bash /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024 ``` ```bash /sbin/mkswap /var/swap.1 ``` ```bash /bin/chmod 0600 /var/swap.1 ``` ```bash /sbin/swapon /var/swap.1 ``` -------------------------------- ### Update Global Packages Source: https://getcomposer.org/doc/03-cli.md Updates all globally installed packages to their latest compatible versions. This ensures you have the most recent versions of your global tools. ```bash php composer.phar global update ``` -------------------------------- ### Prefer stable package versions Source: https://getcomposer.org/doc/03-cli.md The --prefer-stable option instructs Composer to prioritize installing the most stable versions of packages available. ```bash php composer.phar require --prefer-stable vendor/package ``` -------------------------------- ### Enable Repository Source: https://getcomposer.org/doc/03-cli.md Re-enable a previously disabled repository. ```bash php composer.phar repo enable packagist.org ``` -------------------------------- ### Disable security blocking Source: https://getcomposer.org/doc/03-cli.md Use --no-security-blocking (or --no-blocking) to allow the installation of packages with security advisories or that are marked as abandoned. ```bash php composer.phar require --no-security-blocking vendor/package ```