PHP依賴管理工具Composer安裝

bboysoul發表於2017-09-02

簡介

Composer是 PHP 用來管理依賴(dependency)關係的工具。你可以在自己的專案中宣告所依賴的外部工具庫(libraries),Composer 會幫你安裝這些依賴的庫檔案。

安裝

首先你得確定你的伺服器中安裝了php

[root@vultr ~]# php -v
PHP 5.6.22 (cli) (built: Aug 25 2017 10:35:17) 
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend Guard Loader v3.3, Copyright (c) 1998-2014, by Zend Technologies

之後執行命令下載composer-setup.php檔案
php -r "copy(`https://getcomposer.org/installer`, `composer-setup.php`);"
接著驗證檔案的hash
php -r "if (hash_file(`SHA384`, `composer-setup.php`) === `669656bab3166a7aff8a7506b8cb2d1c292f042046c5a994c43155c0be6190fa0355160742ab2e1c88d40d5be660b410`) { echo `Installer verified`; } else { echo `Installer corrupt`; unlink(`composer-setup.php`); } echo PHP_EOL;"
出現Installer verified表示驗證成功
之後執行安裝

[root@vultr ~]# php composer-setup.php
All settings correct for using Composer
Downloading...

Composer (version 1.5.1) successfully installed to: /root/composer.phar
Use it: php composer.phar

接著刪除安裝指令碼
php -r "unlink(`composer-setup.php`);"
可以執行更新來驗證是不是安裝成功
composer selfupdate

使用

composer install
注意如果報錯的話,可以把php.ini中disable_functions這行註釋了

使用國內的Composer映象

因為國外的Composer映象網速很慢,所以一般使用國內的,一條命令搞定
composer config -g repo.packagist composer https://packagist.phpcomposer.com

詳細的可以看
https://getcomposer.org/

Have Fun


相關文章