Composer 踩坑之 require

异常一:file could not be downloaded

使用 composer require 安装依赖包时,出现 file could not be downloaded

Jason:package jason$ composer require "overtrue/package-builder" --prefer-source


  [Composer\Downloader\TransportException]
  The "https://packagist.phpcomposer.com/p/provider-2019-01%24fea7e532df036d6561316b44b5194b84d8bdb92b6c81cf8f07d0afb
  25b0a2b05.json" file could not be downloaded (HTTP/1.1 404 Not Found)


require [--dev] [--prefer-source] [--prefer-dist] [--no-progress] [--no-suggest] [--no-update] [--no-scripts] [--update-no-dev] [--update-with-dependencies] [--update-with-all-dependencies] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [--sort-packages] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--] []...

Jason:package jason$

这是切换 Compser 源引起的,
方式一(推荐):可以切换下其它的 composer 源,如:切换到 packagist.laravel-china.org

composer config -g repo.packagist composer https://packagist.laravel-china.org

方式二:可以多次尝试下,无法解决时执行下 composer update;在这里通过 composer update 后可正常安装依赖。

Jason:package jason$ composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating autoload files
Jason:package jason$
Jason:package jason$

Jason:package jason$ composer require "overtrue/package-builder" --prefer-source
Using version ^1.0 for overtrue/package-builder
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 7 installs, 0 updates, 0 removals
  - Installing symfony/polyfill-ctype (v1.11.0): Cloning 82ebae0220 from cache
...

异常二:[Runtime Exception] vendor does not exist and could not be created

使用 root 进行 composer 安装时(尽量避免使用 root 执行,特别是生产环境),出现:

[root@vm shop]# composer require encore/laravel-admin "1.6.8"
Do not run Composer as root/super user! See https://getcomposer.org/root for details
^C
Installation failed, reverting ./composer.json to its original content.
[root@vm shop]#

切换到普通用户,又再次出现权限不够:

[jason@vm shop]$ composer require encore/laravel-admin "1.6.8"
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 5 installs, 0 updates, 0 removals


  [RuntimeException]
  /home/www/shop/vendor/doctrine/event-manager does not exist and could not be created.


require [--dev] [--prefer-source] [--prefer-dist] [--no-progress] [--no-suggest] [--no-update] [--no-scripts] [--update-no-dev] [--update-with-dependencies] [--update-with-all-dependencies] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [--sort-packages] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--] []...

[jason@vm shop]$

项目本身是由 FTP 用户上传上来的,所以普通用户 jason 对其权限不足,首先考虑为其添加 www,ftp 用户组:

sudo usermod -a -G www jason
sudo usermod -a -G ftp jason

仍然不行。
最后只好将 vendor 的属主改为普通用户 jason

[jason@vm shop]$ sudo chown -R jason:jason vendor/
[jason@vm shop]$

再次安装:

[jason@vm shop]$ composer require encore/laravel-admin "1.6.8"
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 5 installs, 0 updates, 0 removals
  - Installing doctrine/event-manager (v1.0.0): Downloading (100%)
  - Installing doctrine/cache (v1.8.0): Downloading (100%)
  - Installing doctrine/dbal (v2.9.2): Downloading (100%)
  - Installing symfony/dom-crawler (v4.2.5): Downloading (100%)
  - Installing encore/laravel-admin (v1.6.8): Downloading (100%)
doctrine/cache suggests installing alcaeus/mongo-php-adapter (Required to use legacy MongoDB driver)
encore/laravel-admin suggests installing intervention/image (Required to handling and manipulation upload images (~2.3).)
encore/laravel-admin suggests installing spatie/eloquent-sortable (Required to built orderable gird.)


  [ErrorException]
  file_put_contents(./composer.lock): failed to open stream: Permission denied


require [--dev] [--prefer-source] [--prefer-dist] [--no-progress] [--no-suggest] [--no-update] [--no-scripts] [--update-no-dev] [--update-with-dependencies] [--update-with-all-dependencies] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [--sort-packages] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--] []...

[jason@vm shop]$

提示 composer.lock 文件没有权限,将 composer.lock 的属主也修改到 jason

[jason@vm shop]$ sudo chown -R jason:jason ./composer.lock
[jason@vm shop]$
[jason@vm shop]$ composer require encore/laravel-admin "1.6.8"
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Writing lock file
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: beyondcode/laravel-dump-server
Discovered Package: encore/laravel-admin
Discovered Package: fideloper/proxy
Discovered Package: laravel/nexmo-notification-channel
Discovered Package: laravel/slack-notification-channel
Discovered Package: laravel/tinker
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Package manifest generated successfully.
[jason@vm shop]$

安装成功。

你可能感兴趣的:(PHP,Composer)