1

I want to install some yii2 extension and want to use them in yii2 framework. While using Composer I am getting Error.

Also I've tried manually adding extension and adding it's content in composer.json still nothing works.

Some some of command include composer.phar file name and I don't have this file in my main project repository. I tried manually adding composer.phar using composer command but still it didn't run.

When I run this command I got error.

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

I got this error

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"

and got this error

[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>]...`
  • Error clearly states that you need to have curl library installed with your PHP – Bizley Jul 26 '19 at 13:40
  • Possible duplicate (or kind of duplicate) of https://stackoverflow.com/questions/19335305/composer-install-error-requires-ext-curl-when-its-actually-enabled – Kevin Wenger Jul 26 '19 at 13:54
  • 1
    Possible duplicate of [Composer install error - requires ext\_curl when it's actually enabled](https://stackoverflow.com/questions/19335305/composer-install-error-requires-ext-curl-when-its-actually-enabled) – Kevin Wenger Jul 26 '19 at 13:55

2 Answers2

1
  1. Use the following command to remove the permission warning and to make sure your user has permissions on the global composer folder.

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

    Note: to lookup which group your user belongs to

    groups kaushalendra
    

    For me, it shows the following groups

    omeraslam : omeraslam sudo www-data docker
    

    after : all are the groups my user is assigned i can use omeraslam as username and omeraslam as group so for me the command will be sudo chown -R omeraslam:omeraslam /home/kaushalendra/.composer

  2. Then run the following command on terminal

    sudo apt-get install php-curl
    

    Then restart apache

    sudo service apache2 restart
    
Muhammad Omer Aslam
  • 22,976
  • 9
  • 42
  • 68
  • Yes finally I got the point, It was permission issue. I've already provide permission to the file but somehow it was not fully granted. After performing these steps I was able to solve this issue. Thanks again for your help. – Kaushalendra Singh Jul 29 '19 at 11:56
0

Apparently, you don't have permissions to write to ./composer.json

You have 2 ways to fix this. Either give write permissions to the user or the group to that user by running chmod XXX composer.json or you can change the owner of the file to the user which composer is using(He probably has those permissions already).

The XXX above should be numbers. You can read here what those numbers are supposed to be, but you probably want something like a 660 or a 770.

Some people might use 777 to fix this issue, but this should !!NOT!! be used, as you do not want others to access files, unless they really need to.

You can change the owner of the file by using chown. It should look something like chown user:group composer.json.

Please, let me know if there is something that you do not understand and I will clarify, as I know it is hard to understand permissions as a new linux user.

Please note, that this is only for the last error, but handling the other errors is similar. You just need to give the user, which composer is using the right permissions for the right files and/or folders. You can use -R flag for handling directories.

Martin Dimitrov
  • 1,304
  • 1
  • 11
  • 25