Composer是什麼?php
Composer 是 PHP 的一個依賴管理工具。它容許你申明項目所依賴的代碼庫,它會在你的項目中爲你安裝他們。html
1.安裝,其餘安裝方法請到Composer官網json
apt-get install composercomposer
執行composer -V 顯示版本信息表明安裝成功;工具
執行composer install出錯ui
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/下);code
若是不在這個目錄下執行命令會出現如下錯誤 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的文件,寫入保存orm
{ "require": { "monolog/monolog": "1.2.*" } }
再次執行命令 composer install ,OK,成功拉取!htm
總結: 使用官網的方法安裝比較緩慢也有可能安裝失敗,因此使用了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便可。