Search code examples
terminalyii2composer-phpubuntu-18.04yii2-extension

Composer is not working for installing yii2 extensions


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>]...`

Solution

    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