安装Composer

首先将PHP的bin目录加入PATH环境变量
[root@localhost ~]# vim /etc/profile
…………………………
unset i
unset -f pathmunge
 
export TIME_STYLE='+%Y年%m月%d日 %H:%M:%S'
export LD_LIBRARY_PATH=/program/libmcrypt/lib:$LD_LIBRARY_PATH
export PATH=/program/mysql/bin:/program/php/bin:$PATH
[root@localhost ~]# shutdown -r now # 重启使环境变量生效
[root@localhost ~]# php -v
PHP 5.6.40 (cli) (built: Feb 26 2019 11:12:33) 
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
[root@localhost ~]# 
 
 
 
开始下载并安装Composer
[root@localhost ~]# curl -sS https://getcomposer.org/installer | php
All settings correct for using Composer
Downloading...
The "https://getcomposer.org/download/1.9.0/composer.phar.sig" file could not be downloaded: SSL: Handshake timed out
Failed to enable crypto
failed to open stream: operation failed
Retrying...
 
Composer (version 1.9.0) successfully installed to: /root/composer.phar
Use it: php composer.phar
 
[root@localhost ~]# mv composer.phar /usr/local/bin/composer
[root@localhost ~]# composer -v # 检查是否安装成功
Do not run Composer as root/super user! See https://getcomposer.org/root for details
   ______
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ / __ `__ / __ / __ / ___/ _ / ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
____/____/_/ /_/ /_/ .___/____/____/___/_/
                    /_/
Composer version 1.9.0 2019-08-02 20:55:32
 
Usage:
  command [options] [arguments]
 
Options:
  -h, --help                     Display this help message
  -q, --quiet                    Do not output any message
  -V, --version                  Display this application version
…………………………
[root@localhost ~]# composer config -g repo.packagist composer https://packagist.phpcomposer.com/ # 切换成国内镜像(下同)
[root@localhost ~]# composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
[root@localhost ~]# composer config -g repo.packagist composer https://mirrors.cloud.tencent.com/composer/
[root@localhost ~]# composer config -g repo.packagist composer https://repo.huaweicloud.com/repository/php/
Do not run Composer as root/super user! See https://getcomposer.org/root for details
[root@localhost ~]#
说明:如果国内镜像出现无法下载包的情况可以切换为别的镜像再重新下载。

如果使用Composer时我们想指定PHP版本,可以用下面的命令
[root@localhost ~]# /program/php-7.2/bin/php /usr/local/bin/composer create-project topthink/think tp

Copyright © 2024 码农人生. All Rights Reserved