Composer 无法安装 yii2 扩展

Composer is not working for installing yii2 extensions

我想安装一些 yii2 扩展,并想在 yii2 框架中使用它们。使用 Composer 时出现错误。

我也试过手动添加扩展名并将其内容添加到 composer.json 中仍然没有任何效果。

一些命令包含 composer.phar 文件名,但我的主项目存储库中没有此文件。我尝试使用 composer 命令手动添加 composer.phar 但它仍然没有 运行.

当我 运行 这个命令时我得到了错误。

composer require dmstr/yii2-adminlte-asset "^2.1"

我遇到了这个错误

Cannot create cache directory /home/kaushalendra/.composer/cache  /repo/https---asset-packagist.org/, or directory is not writable.     Proceeding without cache
Cannot create cache directory /home/kaushalendra/.composer/cache/repo/https---repo.packagist.org/, or directory is not writable. Proceeding without cache
Cannot create cache directory /home/kaushalendra/.composer/cache/files/, or directory is not writable. Proceeding without cache
./composer.json has been updated
Cannot create cache directory /home/kaushalendra/.composer/cache    /repo/https---asset-packagist.org/, or directory is not writable.     Proceeding without cache
Cannot create cache directory /home/kaushalendra/.composer/cache/repo/https---repo.packagist.org/, or directory is not writable. Proceeding without cache
Cannot create cache directory /home/kaushalendra/.composer/cache/files/, or directory is not writable. Proceeding without cache
 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- codeception/base 2.5.6 requires ext-curl * -> the requested    PHP extension curl is missing from your system.
- codeception/base 2.5.6 requires ext-curl * -> the requested PHP extension curl is missing from your system.
- codeception/base 2.5.6 requires ext-curl * -> the requested PHP extension curl is missing from your system.
- Installation request for codeception/base (locked at 2.5.6, required as ^2.4.0) -> satisfiable by codeception/base[2.5.6].
To enable extensions, verify that they are enabled in your .ini files:
- /etc/php/7.3/cli/php.ini
- /etc/php/7.3/cli/conf.d/10-opcache.ini
- /etc/php/7.3/cli/conf.d/10-pdo.ini
- /etc/php/7.3/cli/conf.d/20-calendar.ini
- /etc/php/7.3/cli/conf.d/20-ctype.ini
- /etc/php/7.3/cli/conf.d/20-exif.ini
- /etc/php/7.3/cli/conf.d/20-fileinfo.ini
- /etc/php/7.3/cli/conf.d/20-ftp.ini
- /etc/php/7.3/cli/conf.d/20-gettext.ini
- /etc/php/7.3/cli/conf.d/20-iconv.ini
- /etc/php/7.3/cli/conf.d/20-json.ini
- /etc/php/7.3/cli/conf.d/20-phar.ini
- /etc/php/7.3/cli/conf.d/20-posix.ini
- /etc/php/7.3/cli/conf.d/20-readline.ini
- /etc/php/7.3/cli/conf.d/20-shmop.ini
- /etc/php/7.3/cli/conf.d/20-sockets.ini
- /etc/php/7.3/cli/conf.d/20-sysvmsg.ini
- /etc/php/7.3/cli/conf.d/20-sysvsem.ini
- /etc/php/7.3/cli/conf.d/20-sysvshm.ini
- /etc/php/7.3/cli/conf.d/20-tokenizer.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.
I've seen somewhere that using this command it will work but getting this error.
composer global require "fxp/composer-asset-plugin:1.0.0-beta4"

遇到这个错误

[ErrorException]
file_put_contents(./composer.json): 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] [--] [<packages>]...`

显然,您没有写入 ./composer.json

的权限

您有两种方法可以解决这个问题。通过 运行 chmod XXX composer.json 向用户或组授予写入权限,或者您可以将文件的所有者更改为作曲家正在使用的用户(他可能已经拥有这些权限)。

上面的XXX应该是数字。您可以阅读 here 这些数字应该是什么,但您可能想要 660 或 770 之类的东西。

有些人可能会使用 777 来解决这个问题,但这应该 !!NOT!!被使用,因为您不希望其他人访问文件,除非他们确实需要。

您可以使用 chown 更改文件的所有者。它应该看起来像 chown user:group composer.json.

如果您有什么不明白的地方,请告诉我,我会澄清,因为我知道作为新 linux 用户很难理解权限。

请注意,这只是针对最后一个错误,但其他错误的处理方式类似。您只需要向用户提供哪个作曲家对正确的文件 and/or 文件夹使用正确的权限。您可以使用 -R 标志来处理目录。

  1. 使用以下命令删除权限警告并确保您的用户对全局 composer 文件夹具有权限。

    sudo chown -R kaushalendra:<YOUR_GROUP> /home/kaushalendra/.composer
    

    注意:要查找您的用户属于哪个组

    groups kaushalendra
    

    对我来说,它显示了以下组

    omeraslam : omeraslam sudo www-data docker
    

    : 之后所有的组都是我的用户分配的我可以使用 omeraslam 作为用户名和 omeraslam 作为组所以对我来说命令将是 sudo chown -R omeraslam:omeraslam /home/kaushalendra/.composer

  2. 然后 运行 在终端

    上执行以下命令
    sudo apt-get install php-curl
    

    然后重启apache

    sudo service apache2 restart