Install Composer under Ubuntu14.04

藏色散人
Release: 2019-08-07 15:03:18
forward
2389 people have browsed it

Composer is a dependency management tool for PHP, so how to install Composer under Ubuntu 14.04? Next, the composer usage tutorial column will explain how to install Composer under Ubuntu 14.04.

Install Composer under Ubuntu14.04

##Download Composer:

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

Install Composer:

/usr/bin/php composer.phar --version
Copy after login

Set global command:

sudo mv composer.phar /usr/local/bin/composer
Copy after login

Check whether the installation and setting are successful:

composer -version
Copy after login

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
Copy after login

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
Copy after login

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"
    }
}
Copy after login

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"
        }
    }
}
Copy after login

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!

Related labels:
source:aliyun.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template