-1

I am trying to make an import excel data to mysql using php and trying to install composer require phpoffice/phpspreadsheet but the error below always appear.

Installation failed, deleting ./composer.json.

In RequireCommand.php line 217:
                                                                                                                          
  No composer.json present in the current directory (./composer.json), this may be the cause of the following exception.  
                                                                                                                          

In PackageDiscoveryTrait.php line 313:
                                                                                                                              
  Package phpoffice/phpspreadsheet has requirements incompatible with your PHP version, PHP extensions and Composer version:  
    - phpoffice/phpspreadsheet 1.25.2 requires ext-zip * but it is not present.

At First, I thought i was because of my php version. I am running xampp with php 7.3 on my macOs. it didnt work. I try to install it in my windows PC which run php 7.4 and it work just fine.

So I remove my 7.3 version and install the 7.4 version into my mac. and it didnt work either.

Gus Dirga
  • 11
  • 4
  • 2
    As the error says: No composer.json present in the current directory. Do you have a composer.json file in the directory you are running composer command? – Roberto Braga Oct 05 '22 at 13:37
  • No. i started with empty folder just like the tutorial i've been watching. It works in the video tutorial and it works on windows PC. btw, how to put composer.json in the current folder i am working? – Gus Dirga Oct 05 '22 at 13:40
  • 4
    Read the last line: it requires "ext-zip", which refers to [the "zip" PHP extension](https://www.php.net/zip). You need to install that extension, probably using whatever tool you used to install PHP itself. – IMSoP Oct 05 '22 at 13:53

1 Answers1

0

There is no compomposer.json in the directory. When starting a new project, you should at first run

composer init

It will do some question to initialize the value in composer.json, which basically are the same you can pass as parameter to the command: https://getcomposer.org/doc/03-cli.md#init

After that you can run composer to install package

Roberto Braga
  • 569
  • 3
  • 8
  • The same error pop up – Gus Dirga Oct 05 '22 at 13:53
  • Then if now you have the composer.json file php is really missing the zip extension. check the accepted answer in https://stackoverflow.com/questions/58290566/install-ext-zip-for-mac adjust the php version accordingly to yours – Roberto Braga Oct 05 '22 at 13:58