ubuntu php composer,Ubuntu16.4下安装Composer

Composer是什么?

Composer 是 PHP 的一个依赖管理工具。它允许你申明项目所依赖的代码库,它会在你的项目中为你安装他们。

1.安装,其他安装方法请到Composer官网

apt-get install composer

执行composer -V 显示版本信息代表安装成功;

执行composer install出错

Changed current directory to /path/.config/composer

Failed to decode response: zlib_decode(): data error

Retrying with degraded mode, check https://getcomposer.org/doc/articles/troubleshooting.md#degraded-mode for more info

Your configuration does not allow connection to http://packagist.org. See https://getcomposer.org/doc/06-config.md#secure-http for details.

http://packagist.org could not be fully loaded, package information was loaded from the local cache and may be out of date

[Composer\Downloader\TransportException]

Your configuration does not allow connection to http://packagist.org. See h

ttps://getcomposer.org/doc/06-config.md#secure-http for details.

require [--dev] [--prefer-source] [--prefer-dist] [--no-plugins] [--no-progress] [--no-update] [--update-no-dev] [--update-with-dependencies] [--ignore-platform-reqs] [--sort-packages] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--] []...

Do not run Composer as root/super user! See https://getcomposer.org/root for details

Composer could not find a composer.json file in /path

To initialize a project, please create a composer.json file as described in the https://getcomposer.org/ "Getting Started" section

2.以上两个错误zlib_decode编码错误和缺少composer.json文件

A:解决方案执行composer update, 执行这条命令时还是出错请到composer所在目录下执行 whereis compser查找所在目录(一般在/path/.config/composer/vendor/fxp/composer-asset-plugin/下);

如果不在这个目录下执行命令会出现以下错误

PHP Fatal error: Call to undefined method Composer\Package\RootPackage::getConfig() in /path/.config/composer/vendor/fxp/composer-asset-plugin/Config/ConfigBuilder.php on line 111

Fatal error: Call to undefined method Composer\Package\RootPackage::getConfig() in /path/.config/composer/vendor/fxp/composer-asset-plugin/Config/ConfigBuilder.php on line 111

B:在当前项目下建一个composer.json的文件,写入保存

{

"require": {

"monolog/monolog": "1.2.*"

}

}

再次执行命令 composer install ,OK,成功拉取!

总结: 使用官网的方法安装比较缓慢也有可能安装失败,所以使用了apt-get进行安装。安装也不容易,也会出各种bug; 1.apt-get install composer;2.检查是否安装成功composer -v;3.更新composer最新版和相关文件 composer update或者composer selfupdate,如果错误whereis查找所在目录一般在 /path/.config/composer/vendor/fxp/composer-asset-plugin/下再次执行 composer update或者composer selfupdate;4.在项目下创建composer.json配置想要拉取的项目版本信息即可;5.再执行composer install即可。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值