42

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.
MrScf
  • 2,407
  • 5
  • 27
  • 40
  • 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. – Michael Berkowski Jan 13 '18 at 14:24
  • I am using the statement `sudo Composer require phpoffice/phpspreadsheet` – MrScf Jan 13 '18 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" – Michael Berkowski Jan 13 '18 at 14:51
  • Yes, I am getting: `failed to open stream: Permission denied` – MrScf Jan 13 '18 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). – Michael Berkowski Jan 13 '18 at 15:03
  • I am getting now this error (updated in my question) – MrScf Jan 13 '18 at 15:15
  • so I am installing ext-dom? – MrScf Jan 13 '18 at 15:15
  • Possible duplicate of [The requested PHP extension dom is missing from your system](https://stackoverflow.com/questions/44952650/the-requested-php-extension-dom-is-missing-from-your-system) – Kurzyx Jan 13 '18 at 15:31

13 Answers13

90

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

MrScf
  • 2,407
  • 5
  • 27
  • 40
  • 16
    For coherence, `sudo apt install php7.0-xml php7.0-gd php7.0-mbstring php7.0-zip` – nicolallias May 28 '18 at 09: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** – Muhammad Omer Aslam Sep 12 '19 at 08:01
  • 1
    Thank you so much! this worked well. Since mine was `php7.2` I changed the`php7.0` to `php7.2` and the other two the same. then it worked prefect! – Kidus Tekeste Apr 18 '20 at 06:18
  • 3
    Better specify php version for every command (`php7.3-xml`, `php7.3-gd`, `php7.3-mbstring`, `php7.3-zip`). – Akshay K Nair Jan 28 '21 at 11:11
  • That commands are solved my problem too. Thank you so much. – Enver Apr 22 '21 at 10:35
22

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

composer install --ignore-platform-reqs
Luisfayre
  • 403
  • 4
  • 5
14

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.

Amr Abdalrahman Ahmed
  • 920
  • 1
  • 14
  • 19
4

In Centos:

sudo yum install gd gd-devel php-gd

Ali Shahnazi
  • 616
  • 1
  • 7
  • 7
4

sudo apt install php-xml

sudo apt install php7.0-gd

sudo apt install php7.0-mbstring

sudo apt install php-zip

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"
    },
jhoskins98
  • 114
  • 5
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

tomerpacific
  • 4,704
  • 13
  • 34
  • 52
Powen Ko
  • 31
  • 3
1

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
xpredo
  • 1,282
  • 17
  • 27
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
Adi Prasetyo
  • 1,006
  • 1
  • 15
  • 41
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

Rahul Yadav
  • 867
  • 11
  • 12
-1

if you are using

$sheet->setAutoFilter(); 

try comment this to test

//$sheet->setAutoFilter();

works for me

Mauricio Paz
  • 107
  • 4
-1

composer require maatwebsite/excel:*

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 31 '22 at 06:19
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/31420062) – जलजनक Apr 01 '22 at 17:28