PHP依赖管理工具Composer安装

简介

Composer是 PHP 用来管理依赖(dependency)关系的工具。你可以在自己的项目中声明所依赖的外部工具库(libraries),Composer 会帮你安装这些依赖的库文件。

安装

首先你得确定你的服务器中安装了php

1
2
3
4
5
[[email protected] ~]# 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表示验证成功
之后执行安装

1
2
3
4
5
6
[[email protected] ~]# 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

欢迎关注我的其它发布渠道