Categories
Blog Magento

Magento 2 installing new php library via composer

Hi,
I had to install php library phpoffice/phpexcel for reading and writing excel files with php. The easiest solution seemed to be to use composer. But running the command
composer require phpoffice/phpexcel
gave me an error:

composer require phpoffice/phpexcel

[Composer\Downloader\TransportException]
Invalid credentials for 'https://repo.magento.com/packages.json', aborting.

require [--dev] [--prefer-source] [--prefer-dist] [--no-plugins] [--no-progress] [--no-update] [--update-no-dev] [--update-with-dependencies] [-ignore-platform-reqs] [--sort-packages] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--] []...

There were a couple of things I had to do to make my composer install the needed library.

Add your public and private keys

In order to use the composer with magento 2 you first need to add the authentication details to your magento. That’s easy-peasy.

  • Go to magento marketplace and sing in to your account or if you have none, then sign up and create the account.
  • Click on Access Keys in your profile. And this will take you to the area with your access keys.
  • Here you’ll see a big orange button “Create new Access Key” – click on it and it will open a modal with input form. In the input field write down you project name (like “text.com”) and click on ok. This will generate both public and private keys.
  • You will now see your access keys in table below.

Now let’s add our access keys to our magento installation.

  • Go to admin area of your store
  • There go to System -> Tools -> Web Setup Wizard
  • Then click on System Configuration and it will open the form with private and public key input.
  • Fill in the needed data by copying the access keys from magento marketplace and click save config

And voila! You should be done now and should be able to run your composer command.

Not working even though i added the keys

If you’re like me, then there will be some difficulties. If you added the access keys and it still gives you the same error then check your composer by running:
composer diagnose

In my case running this gave me this notice:

composer diagnose
Checking composer.json: FAIL
The version field is present, it is recommended to leave it out if the package is published on Packagist.
Defining autoload.psr-0 with an empty namespace prefix is a bad idea for performance
require.composer/composer : unbound version constraints (@alpha) should be avoided
Checking platform settings: OK
Checking git settings: OK
Checking http connectivity to packagist: OK
Checking https connectivity to packagist: OK
Checking github.com rate limit: OK
Checking disk free space: OK
Checking pubkeys:
Tags Public Key Fingerprint: xxxxxxxx xxxxxxxx xxxxxxx xxxxxxx
Dev Public Key Fingerprint: xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxx
OK
Checking composer version: FAIL
You are not running the latest stable version, run `composer self-update` to update (1.0.3 => 1.4.2)

It turned up that my composer version was old. So i simply run the next command:
composer self-update

And updated my composer to new stable version.
After it completed the update I again ran my line:

composer require phpoffice/phpexcel

And guess what – i worked! I finally installed the needed library.
I really hope this little post helps some one whose composer is not playing along.

Cheers!

By Iva Korlevic

I'm a web programmer that started working with web pages in 2008 by programming simple HTML/CSS webpages. I finished Faculty of electrical engineering in April 2010 and started working in Inchoo in May 2010. During the time in Inchoo I worked on Zend applications, Magento stores and a few Wordpress projects. I left Inchoo in January 2012 and worked for a couple of months in Gauss Informatika as Zend teacher and team leader. In May 2012 I left Gauss Informatika and joined the team at NTH Media. For next 6 months I worked on various mobile and Wordpress projects. In the February 2013 together with MArin Blazevic I opened Proodos. I'm still continuing my work as Zend and Magento programmer.
In summer 2015 I also started to work for Webbite Media GMBH and on 19th August 2015 I passed Magento Certification Exam and am now Magento Certified Developer.

Leave a Reply

Your email address will not be published. Required fields are marked *



This site uses Akismet to reduce spam. Learn how your comment data is processed.