1

我想安装一些 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>]...`
4

2 回答 2

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

    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
    
于 2019-07-26T15:34:43.363 回答
0

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

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

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

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

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

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

请注意,这仅适用于最后一个错误,但处理其他错误是类似的。您只需要为用户提供对正确文件和/或文件夹使用正确权限的作曲家。您可以使用-R标志来处理目录。

于 2019-07-26T13:47:11.803 回答