Home >Development Tools >composer >How to check whether composer installs package details
This guide provides a step-by-step approach to checking your Composer package installations, covering various aspects from listing all installed packages to verifying their integrity.
The simplest way to list all installed Composer packages and their versions is by using the composer show
command. This command, when executed without any arguments, provides a comprehensive list of all packages installed within your current project's directory. Each line represents a package, showing its name, version, and optionally, the source it was installed from (e.g., Packagist).
Here's how to do it:
cd
command to navigate to the root directory of your project where your composer.json
and composer.lock
files are located. For example: cd /path/to/your/project
composer show
command: Type composer show
and press Enter.<code>[root@localhost project]# composer show monolog/monolog v2.3.0 A flexible logging library for PHP psr/log v1.1.4 Common interface for logging libraries symfony/console v6.1.4 Provides Symfony's Console component. symfony/event-dispatcher v6.1.4 Provides Symfony's EventDispatcher component. symfony/http-foundation v6.1.4 Provides Symfony's HttpFoundation component. symfony/routing v6.1.4 Provides Symfony's Routing component. ...</code>
This output clearly shows the package name, version, and optionally the description. This is the quickest way to get an overview of your installed packages and their versions. You can also use the -o
or --format=json
flag to output the information in a machine-readable JSON format. For instance, composer show -o
will show a more compact output, suitable for scripting.
To obtain detailed information about a specific package, you can use the composer show
command with the package name as an argument. This provides a more comprehensive view, including the description, authors, dependencies, and other relevant metadata.
Here's how:
composer show
command with the package name: Replace <package_name>
with the actual name of the package you want to inspect. For example: composer show monolog/monolog
composer show
without arguments. You will see information about the package's requirements, suggested packages, and other relevant details.Composer utilizes checksums (specifically SHA-1 and SHA-256 hashes) to ensure the integrity of installed packages. The composer install
and composer update
commands automatically verify these checksums against those provided by the package repository (usually Packagist). However, if you need to manually check the integrity, you can investigate the composer.lock
file. This file contains the exact versions and checksums of all installed packages and their dependencies. Any discrepancy between the checksums in the composer.lock
file and the actual downloaded files indicates a potential security compromise or corruption.
While there isn't a dedicated Composer command to explicitly verify checksums in a human-readable format beyond the automatic check during installation/update, inspecting the composer.lock
file itself provides the necessary information. The composer.lock
file is a crucial part of your project's dependency management and version control. You should always commit it to your version control system (like Git). If you suspect a problem, comparing the checksums listed in composer.lock
with the actual files on your system would be necessary, though this would usually require external tools. Any mismatch would require re-running composer install
or composer update
to resolve the issue. A compromised composer.lock
file should be treated with extreme caution.
The above is the detailed content of How to check whether composer installs package details. For more information, please follow other related articles on the PHP Chinese website!