47

I want to write a Script using the package Phpspreadsheet. I am not experience in php. I am trying to add the reference to my script through sudo composer require phpoffice/phpspreadsheet. But it doesn't work. I am getting the error: In stallation failed, deleting composer.json....If have no idea why it is not working. Any idea?

Detailed Error:

Your requirements could not be resolved to an installable set of packages.

Problem 1
- Installation request for phpoffice/phpspreadsheet ^1.0 -> satisfiable by phpoffice/phpspreadsheet[1.0.0].
- phpoffice/phpspreadsheet 1.0.0 requires ext-dom * -> the requested PHP extension dom is missing from your system.

To enable extensions, verify that they are enabled in those .ini files:
- /etc/php/7.0/cli/php.ini
- /etc/php/7.0/cli/conf.d/10-mysqlnd.ini
- /etc/php/7.0/cli/conf.d/10-opcache.ini
- /etc/php/7.0/cli/conf.d/10-pdo.ini
- /etc/php/7.0/cli/conf.d/20-calendar.ini
- /etc/php/7.0/cli/conf.d/20-ctype.ini
- /etc/php/7.0/cli/conf.d/20-exif.ini
- /etc/php/7.0/cli/conf.d/20-fileinfo.ini
- /etc/php/7.0/cli/conf.d/20-ftp.ini
- /etc/php/7.0/cli/conf.d/20-gettext.ini
- /etc/php/7.0/cli/conf.d/20-iconv.ini
- /etc/php/7.0/cli/conf.d/20-json.ini
- /etc/php/7.0/cli/conf.d/20-mcrypt.ini
- /etc/php/7.0/cli/conf.d/20-mysqli.ini
- /etc/php/7.0/cli/conf.d/20-pdo_mysql.ini
- /etc/php/7.0/cli/conf.d/20-phar.ini
- /etc/php/7.0/cli/conf.d/20-posix.ini
- /etc/php/7.0/cli/conf.d/20-readline.ini
- /etc/php/7.0/cli/conf.d/20-shmop.ini
- /etc/php/7.0/cli/conf.d/20-sockets.ini
- /etc/php/7.0/cli/conf.d/20-sysvmsg.ini
- /etc/php/7.0/cli/conf.d/20-sysvsem.ini
- /etc/php/7.0/cli/conf.d/20-sysvshm.ini
- /etc/php/7.0/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.
7
  • 2
    You probably should not be using sudo. Typically composer dependencies would be installed in the project space rather than as a superuser. But if you scroll up in the composer output there should be more information. I just tried it and got phpoffice/phpspreadsheet 1.0.0 requires ext-zip * -> the requested PHP extension zip is missing from your system meaning I do not have the zip extension installed. You may have that problem or other similar issues. Jan 13, 2018 at 14:24
  • I am using the statement sudo Composer require phpoffice/phpspreadsheet
    – MrScf
    Jan 13, 2018 at 14:34
  • My point is that you should probably only use composer require phpoffice/phpspreadsheet without sudo. Do so and post the full error output. It should provide more than just "installation failed" Jan 13, 2018 at 14:51
  • Yes, I am getting: failed to open stream: Permission denied
    – MrScf
    Jan 13, 2018 at 14:56
  • Okay then you probably don't have write access where you are trying to install this and sudo is necessary. So use sudo but include the full error output (edit your original post rather than comment). Jan 13, 2018 at 15:03

13 Answers 13

93

So I should install

sudo apt install php-xml

sudo apt install php7.0-gd

sudo apt install php7.0-mbstring

sudo apt install php-zip

5
  • 16
    For coherence, sudo apt install php7.0-xml php7.0-gd php7.0-mbstring php7.0-zip May 28, 2018 at 9:15
  • 2
    has anyone been able to install the zip extension for php7.2 ? it keep on saying E: Unable to locate package php7.2-zip E: Couldn't find any package by regex 'php7.2-zip' i have tried alot of variations but none work, i have PHP Version 7.2.17-1+ubuntu14.04.1+deb.sury.org+3 Sep 12, 2019 at 8:01
  • 1
    Thank you so much! this worked well. Since mine was php7.2 I changed thephp7.0 to php7.2 and the other two the same. then it worked prefect! Apr 18, 2020 at 6:18
  • 3
    Better specify php version for every command (php7.3-xml, php7.3-gd, php7.3-mbstring, php7.3-zip). Jan 28, 2021 at 11:11
  • That commands are solved my problem too. Thank you so much.
    – Enver
    Apr 22, 2021 at 10:35
25

I had the same problem, i fix it by doing this

composer install --ignore-platform-reqs
3
  • 4
    Any explanation ? Aug 19, 2021 at 19:59
  • @PriyankMotivaras by using the --ignore-platform-req option, you instruct Composer to skip the platform requirement checks and proceed with the installation regardless of any mismatches.
    – talha2k
    Jul 4, 2023 at 21:31
  • it's still not working in my case
    – Moeez
    Sep 28, 2023 at 10:38
15

also while running composer install/update or install new package adds

--ignore-platform-reqs

at the end of command, while add/install successfully for different environments.

0
4

In Centos:

sudo yum install gd gd-devel php-gd

4

sudo apt install php-xml

sudo apt install php7.0-gd

sudo apt install php7.0-mbstring

sudo apt install php-zip

1
  • in my case i was missing php7.3-zip, after installing the error disappeared
    – levis
    Oct 27, 2020 at 20:10
3

Please read the error message "requires ext-dom". It is complaining about a missing package or in this case php extension. Generally, when you can't install a package you can look at the required packages in its composer.json to see the complete list.

phpoffice (1.1.0 in this case) requires the following:

   "require": {
        "php": "^5.6|^7.0",
        "ext-ctype": "*",
        "ext-dom": "*",
        "ext-gd": "*",
        "ext-iconv": "*",
        "ext-libxml": "*",
        "ext-mbstring": "*",
        "ext-SimpleXML": "*",
        "ext-xml": "*",
        "ext-xmlreader": "*",
        "ext-xmlwriter": "*",
        "ext-zip": "*",
        "ext-zlib": "*",
        "psr/simple-cache": "^1.0"
    },
    "require-dev": {
        "tecnickcom/tcpdf": "^6.2",
        "squizlabs/php_codesniffer": "^2.7",
        "phpunit/phpunit": "^5.7",
        "dompdf/dompdf": "^0.8.0",
        "mpdf/mpdf": "^7.0.0",
        "jpgraph/jpgraph": "^4.0",
        "friendsofphp/php-cs-fixer": "@stable"
    },
2

type

 php -v

if php7 type

sudo apt install php-xml
sudo apt install php7.0-gd
sudo apt install php7.0-mbstring
sudo apt install php-zip

if php8 type

sudo apt install php-xml
sudo apt install php8.0-gd
sudo apt install php8.0-mbstring
sudo apt install php-zip
1

The error message display miss. I had the same problem, fix it by doing this. Please read the error message "requires ext-dom".

please install php7.1-dom

in my case, PHP is 7.1 below is I did and working now.

sudo apt-get install php7.1 php7.1-cli php7.1-common php7.1-json php7.1-opcache php7.1-mysql php7.1-mbstring php7.1-mcrypt php7.1-zip php7.1-fpm sudo apt install php-xml php7.1-gd php7.1-dom

1

I encountered the same problem and I solve it using the command composer install --ignore-platform-reqs

0

If you are arch user edit /etc/php74/php.ini or whichever version you use. Makes sure the extension is installed and the gd extension is uncommented.

extension=gd
0

Check your system PHP version

If your system PHP 8.0 then run the below command

sudo apt-get install php8.0-xml php8.0-gd php8.0-mbstring php8.0-zip

If your system PHP 7.0 then run the below command

sudo apt-get install php7.0-xml php7.0-gd php7.0-mbstring php7.0-zip

-1

if you are using

$sheet->setAutoFilter(); 

try comment this to test

//$sheet->setAutoFilter();

works for me

-1

composer require maatwebsite/excel:*

2

Not the answer you're looking for? Browse other questions tagged or ask your own question.