1. Installation Composer: Partial installation
To really get Composer, we need to do two things. First install Composer (again, which means it will be downloaded to your project):
curl -sS https://getcomposer.org/installer | php
Note:
During installation, you may be unable to download the installation because the system comes with PHP, which should be removed from the system with PHP and then added to the system variables when the environment is installed.
If the above method fails for some reason, you can also php
download the installer via >:
php -r "readfile(‘https://getcomposer.org/installer‘);" | php
This will check some of the PHP settings and then download composer.phar
them to your working directory. This is a binary file of Composer. This is a PHAR package (PHP archive), which is a PHP archive format that helps users perform some operations on the command line.
You can --install-dir
specify the installation directory for Composer (which can be an absolute or relative path) by using the options:
curl -sS https://getcomposer.org/installer | php -- --install-dir=bin
Global Installation
You can put this file anywhere. If you put it in the system PATH
directory, you will be able to access it globally. In Unix-like systems, you can even use them without a php
prefix.
You can execute these commands to make composer
global calls on your system:
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
Note: If the appeal command fails because of permission execution, use sudo again to try to run
mv
that line of command.
Now you only need to run the composer
command to use Composer without the need to enterphp composer.phar
2. Replace the domestic mirror
There are two ways to enable this mirroring service:
- System global Configuration: Adds the configuration information to the Composer global configuration file
config.json
. See "Example 1"
- Single project configuration: Adds configuration information to a
composer.json
file in a project. See "Example 2"
Example 1: Modifying the global configuration file for composer (recommended)
Open a command-line window (Windows user) or console (Linux, MAC user) and execute the following command:
composer config -g repo.packagist composer https://packagist.phpcomposer.com
Example 2: Modify the configuration file for the current project composer.json
:
Open a command-line window (Windows user) or console (Linux, MAC user), enter the root directory of your project ( composer.json
that is, the directory where the files are located), and execute the following command:
composer config repo.packagist composer https://packagist.phpcomposer.com
The above command will automatically add the mirrored configuration information at the end of the file in the current project composer.json
(you can also manually add it yourself):
"repositories": {
"packagist": {
"type": "composer",
"url": "https://packagist.phpcomposer.com"
}}
Take the composer.json
configuration file for the Laravel project as an example, following the above command (note the last few lines):
{
"Name": "Laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["Framework", "Laravel"],
"License": "MIT",
' Type ': ' Project ',
"Require": {
"PHP": ">=5.5.9",
"Laravel/framework": "5.2.*"
},
"Require-dev": {
"Fzaninotto/faker": "~1.4",
"Mockery/mockery": "0.9.*",
"Phpunit/phpunit": "~4.0",
"Symfony/css-selector": "2.8.*|3.0.*",
"Symfony/dom-crawler": "2.8.*|3.0.*"
},
"AutoLoad": {
"Classmap": [
"Database"
],
"Psr-4": {
"app\\": "app/"
}
},
"Autoload-dev": {
"Classmap": [
"Tests/testcase.php"
]
},
"Scripts": {
"Post-root-package-install": [
"Php-r \" Copy ('. Env.example ', '. env '); \ ""
],
"Post-create-project-cmd": [
"PHP Artisan key:generate"
],
"Post-install-cmd": [
"PHP Artisan clear-compiled",
"PHP Artisan Optimize"
],
"Pre-update-cmd": [
"PHP Artisan clear-compiled"
],
"Post-update-cmd": [
"PHP Artisan Optimize"
]
},
"Config": {
"Preferred-install": "Dist"
},
"Repositories": {
"Packagist": {
"Type": "Composer",
"url": "Https://packagist.phpcomposer.com"
}
}}
OK, everything is done! Try composer install
to experience the speed of flying!
Image description:
In general, the data of the installation package (mainly the zip file) is usually downloaded from the download github.com
, and the metadata of the installation package is downloaded from the download packagist.org
.
However, due to well-known reasons, foreign websites are slow to connect and may be "wall" or "nonexistent" at any time.
"Packagist China Full-volume mirror" does is to cache all the installation package and metadata to the domestic engine room and through the domestic CDN to accelerate, so that no longer to the foreign site to initiate the request, so as to accelerate composer install
composer update
the process, and faster and more stable. As a result packagist.org
, github.com
you can still download and update the installation package even if, in the event of a failure (mainly the connection speed is too slow and the wall is blocked).
Use the Help site: http://www.phpcomposer.com/
Installation and use of 7.Composer