Ubuntu16.4下安装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] [--] [<packages>]...
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即可。

原文链接:https://www.f2er.com/ubuntu/353300.html

猜你在找的Ubuntu相关文章