Composer 是个包管理工具
在项目中使用它会很方便
本文中用 PHP 安装
1、下载安装
执行命令 curl -sS https://getcomposer.org/installer | php
2、配置环境变量
mv composer.phar /usr/local/bin/composer
3、设置国内镜像
composer config -g repo.packagist composer https://packagist.phpcomposer.com
4、遇到的问题
Q1:/usr/bin/env: php: No such file or directory
A1:找不到 php 执行文件,cp /usr/local/php/bin/php /usr/local/bin/php
Q2:执行 composer 抛出 Killed
A2:缓存不足导致,linux 增加缓存
free -m
mkdir -p /var/_swap_
cd /var/_swap_
dd if=/dev/zero of=swapfile bs=1M count=2000
mkswap swapfile
swapon swapfile
echo “/var/_swap_/swapfile none swap sw 0 0” >> /etc/fstab
free -m
Q3:
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- league/flysystem 1.0.53 requires ext-fileinfo * -> the requested PHP extension fileinfo is missing from your system.
- league/flysystem 1.0.53 requires ext-fileinfo * -> the requested PHP extension fileinfo is missing from your system.
- league/flysystem 1.0.53 requires ext-fileinfo * -> the requested PHP extension fileinfo is missing from your system.
- Installation request for league/flysystem (locked at 1.0.53) -> satisfiable by league/flysystem[1.0.53].
To enable extensions, verify that they are enabled in your .ini files:
- /usr/local/php/lib/php.ini
You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.
Installation failed, reverting ./composer.json to its original content.
A3:安装 fileinfo 扩展包
cd /usr/local/src/php-7.3.4/ext/fileinfo/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config