Home>Article>Development Tools> Install Composer under Ubuntu14.04

Install Composer under Ubuntu14.04

藏色散人
藏色散人 forward
2019-08-07 15:03:18 2265browse

Composer is a dependency management tool for PHP, so how to install Composer under Ubuntu 14.04? Next, thecomposer usage tutorialcolumn will explain how to install Composer under Ubuntu 14.04.

Install Composer under Ubuntu14.04

##Download Composer:

curl -sS https://getcomposer.org/installer | php

Install Composer:

/usr/bin/php composer.phar --version

Set global command:

sudo mv composer.phar /usr/local/bin/composer

Check whether the installation and setting are successful:

composer -version

If successful, the following picture will appear

Install Composer under Ubuntu14.04

## Packagist / Composer China Full Image

Method 1: Modify the global configuration file of composer (recommended method)

Open the command line window (windows users) or console (Linux, Mac users) and execute the following command:

composer config -g repo.packagist composer https://packagist.phpcomposer.com

Method 2: Modify the composer.json configuration file of the current project:

Open the command line window (windows users) or console (Linux, Mac users), enter the root directory of your project (that is, the directory where the composer.json file is located ), execute the following command:

composer config repo.packagist composer https://packagist.phpcomposer.com

The above command will automatically add the image configuration information at the end of the composer.json file in the current project (you can also add it manually):

"repositories": { "packagist": { "type": "composer", "url": "https://packagist.phpcomposer.com" } }

Taking the composer.json configuration file of the laravel project as an example, after executing the above command, it will look as follows (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.*" }, "config": { "preferred-install": "dist" }, "repositories": { "packagist": { "type": "composer", "url": "https://packagist.phpcomposer.com" } } }

OK, everything is done! Try composer install to experience the incredible speed!

Mirror principle:

Under normal circumstances, the data of the installation package (mainly zip files) is usually downloaded from github.com, and the metadata of the installation package Downloaded from packagist.org.

However, due to well-known reasons, the connection speed of foreign websites is very slow, and may be "walled" or even "non-existent" at any time.

What "Packagist China Full Mirror" does is to cache all installation packages and metadata to domestic computer rooms and accelerate them through domestic CDNs, so that there is no need to make requests to foreign websites, thereby accelerating composer The process of install and composer update is faster and more stable. Therefore, even if packagist.org or github.com fails (mainly because the connection speed is too slow or blocked), you can still download and update the installation package.

The above is the detailed content of Install Composer under Ubuntu14.04. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:aliyun.com. If there is any infringement, please contact admin@php.cn delete