I. Installation
Cd path-to-your-project
Curl-sS https://getcomposer.org/installer | php
# Composer successfully installed to:/tmp/composer. phar
# Use it: php composer. phar
If this prompt is displayed, it is because php is not in the $ PATH environment variable of the system.
Command not found: php
Solution:
Create a soft connection for the current php path
Ln-s/usr/local/php/bin/php/usr/local/bin/php
Check composer carefully. the phar permission should be 755, that is,-rwxr-xr-x, indicating that all other persons in the file have the execution permission, so if we move it to/usr/local/bin/, it will be available globally!
Mv composer. phar/usr/local/bin/composer
II. Use
Use-h to view help
Composer-h
Usage:
Help [-- xml] [-- format = "..."] [-- raw] [command_name]
Arguments:
Command The command to execute
Command_name The command name (default: "help ")
Options:
-- Xml To output help as XML
-- Format To output help in other formats (default: "txt ")
-- Raw To output raw command help
-- Help (-h) Display this help message
-- Quiet (-q) Do not output any message
-- Verbose (-v | vv | vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
-- Version (-V) Display this application version
-- Ansi Force ANSI output
-- No-ansi Disable ANSI output
-- No-interaction (-n) Do not ask any interactive question
-- Profile Display timing and memory usage information
-- Working-dir (-d) If specified, use the given directory as working directory.
Help:
The help command displays help for a given command:
Php/usr/local/bin/composer help list
You can also output the help in other formats by using the -- format option:
Php/usr/local/bin/composer help -- format = xml list
To display the list of available commands, please use the list command.
It seems that to find all the commands, you need to run php/usr/local/bin/composer help list
Let's try it.
Php/usr/local/bin/composer list
______
/____/_______________________________
///__\/__'__\/__\/__\/___/_\/___/
//___//_////////_///_/(__)__//
\____/\____/_//_//_/.___/\____/____/\___/_/
/_/
Composer version 1.0-dev (4f80e7ff68466cab970c22b316725b8058c32970) 00:03:48
Usage:
Command [options] [arguments]
Options:
-- Help (-h) Display this help message
-- Quiet (-q) Do not output any message
-- Verbose (-v | vv | vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
-- Version (-V) Display this application version
-- Ansi Force ANSI output
-- No-ansi Disable ANSI output
-- No-interaction (-n) Do not ask any interactive question
-- Profile Display timing and memory usage information
-- Working-dir (-d) If specified, use the given directory as working directory.
Available commands:
About Short information about Composer
Archive Create an archive of this composer package
Browse Opens the package's repository URL or homepage in your browser.
Clear-cache Clears composer's internal package cache.
Clearcache Clears composer's internal package cache.
Config Set config options
Create-project Create new project from a package into given directory.
Depends Shows which packages depend on the given package
Diagnose Diagnoses the system to identify common errors.
Dump-autoload Dumps the autoloader
Dumpautoload Dumps the autoloader
Global Allows running commands in the global composer dir ($ COMPOSER_HOME ).
Help Displays help for a command
Home Opens the package's repository URL or homepage in your browser.
Info Show information about packages
Init Creates a basic composer. json file in current directory.
Install installthe project dependencies from the composer. lock file if present, or falls back on the composer. json.
Licenses Show information about licenses of dependencies
List Lists commands
Remove Removes a package from the require or require-dev
Require Adds required packages to your composer. json and installthem
Run-script Run the scripts defined in composer. json.
Search Search for packages
Self-update Updates composer. phar to the latest version.
Selfupdate Updates composer. phar to the latest version.
Show Show information about packages
Status Show a list of locally modified packages
Update Updates your dependencies to the latest version according to composer. json, and updates the composer. lock file.
Validate Validates a composer. json
III. Domestic images
To better use composer, we use phpcomposer for domestic Image acceleration. The specific usage is very simple. You can refer to the instructions on the official website!
IV. Use composer in the project
For example, what if laravel and monolog need to be used in our project?
First, search for the required package name in packagist.org. In this way, we get the package name monolog/monolog, which is the same as laravel.
Next, we need to confirm the version. We can see the official website prompt:
{
"Require ":{
"Vendor/package": "1.3.2", # specify the version
"Vendor/package2": "1. *", # use wildcards to facilitate future updates
"Vendor/package2 ":"~ 1.3 ", # indicates version 1.3 <= X <2.0
"Vendor/package3": "> = 2.0.3", # specifies a range.
"Vendor/package3": "> = 2.0.3-dev" # By default, composer obtains the stable version, but if-dev is specified, the dev version will be downloaded.
}
}
For more information, see Package Versions.
Create the file composer. json in the project root directory.
{
"Require ":{
"Monolog/monolog": "1. 0 .*"
}
}
You can also automatically generate this composer. json, and run the command composer init -- require "monolog/monolog: 1. 0. *"-n