324

I'm running laravel 5.4 on Ubuntu 16.04 server with PHP7. trying to install cviebrock/eloquent-sluggable package throw some error:

pish@let:/home/sherk/ftp/www$ sudo composer require cviebrock/eloquent-sluggable
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Using version ^4.2 for cviebrock/eloquent-sluggable
./composer.json has been updated
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
    - phpunit/php-code-coverage 4.0.7 requires ext-dom * -> the requested PHP extension dom is missing from your system.
    - phpunit/php-code-coverage 4.0.7 requires ext-dom * -> the requested PHP extension dom is missing from your system.
    - Installation request for phpunit/php-code-coverage (installed at 4.0.7) -> satisfiable by phpunit/php-code-coverage[4.0.7].

  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-gd.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-mbstring.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.

I have no problem installing this package on local version of the app .

Payam Khaninejad
  • 7,692
  • 6
  • 45
  • 55
alex
  • 7,551
  • 13
  • 48
  • 80

4 Answers4

699

First of all, read the warning! It says do not run composer as root! Secondly, you're probably using Xammp on your local which has the required php libraries as default.

But in your server you're missing ext-dom. php-xml has all the related packages you need. So, you can simply install it by running:

sudo apt-get update
sudo apt install php-xml

Most likely you are missing mbstring too. If you get the error, install this package as well with:

sudo apt-get install php-mbstring

Then run:

composer update
composer require cviebrock/eloquent-sluggable
Community
  • 1
  • 1
Anar Bayramov
  • 11,158
  • 5
  • 44
  • 64
  • 2
    thanks . if i dont use `sudo` for running composer, get this error :`Could not read /home/pish/.composer/auth.json file_get_contents(/home/pish/.composer/auth.json): failed to open stream: Permission denied ` – alex Apr 14 '17 at 09:27
  • 4
    its a permission issue search for chmod and chown commands. Change permission and owner of this folder you will be fine. – Anar Bayramov Apr 14 '17 at 09:36
  • @rodrane there's a typo in your code for installing the `php-mbstring` package, it should be `sudo apt-get`. Other than that; it works like a charm. Thanks! – Robin B Jun 04 '17 at 19:11
  • I installed php7.0-xml on my machine but composer still throw me this error when I do a `composer install` – Salustiano Muniz Aug 04 '17 at 16:57
  • @SalustianoMuniz You might have to enable the modules in PHP. For example, use `sudo phpenmod xml` and do the same for `xmlreader` & `xmlwriter`. Then restart your server (if apache: `sudo service apache2 restart`) and try to install again. – Tim Visée Aug 15 '17 at 14:58
  • 1
    Or sudo apt-get install php7.2-xml if you are into 7.2.x – cucu8 Feb 23 '18 at 10:07
  • : Unable to locate package php7.1-xml E: Couldn't find any package by glob 'php7.1-xml' E: Couldn't find any package by regex 'php7.1-xml' – Rafael Lima May 20 '18 at 13:55
  • Thanks fix my problem.For php 7.2 use this sudo apt-get install php7.2-xml – Arman H Mar 17 '19 at 13:03
  • 1
    Is there somewhere we can match missing extensions to actual packages? Only after trying (and failing) to install php7.3-dom, php7.3-extdom, php7.3-ext-dom did I finally google to find the right package php7.3-xml here. – Jon Freynik Jun 09 '19 at 20:04
  • php-zip package is also needed. – 8ctopus Apr 22 '20 at 14:53
  • sudo apt install php-xml is the key – simaremare Dec 06 '20 at 08:50
  • You need to install php-xml based on your PHP version. eg: if your PHP version is 7.4 => sudo apt-get install php7.4-xml – Randika Jun 08 '23 at 23:30
107

sudo apt install php-xml will work but the thing is it will download the plugin for the latest PHP version.

If your PHP version is not the latest, then you can add version in it:

# PHP 7.1
sudo apt install php7.1-xml

# PHP 7.2:
sudo apt install php7.2-xml

# PHP 7.3
sudo apt install php7.3-xml


# PHP 7.4
sudo apt install php7.4-xml

# PHP 8
sudo apt install php-xml
Player1
  • 2,878
  • 2
  • 26
  • 38
  • 3
    I'm running 7.3 and someone else was saying to install "php-xml", so I did, but I still had the exact same problem. Once you see how simple it is it's easy to understand, but I completely missed it until seeing this answer. Installing php7.3-xml solved my problem. – Andrew Fox Dec 11 '20 at 19:07
  • 1
    Thank you, this is the solution. By mistake the php 8 extension was installed. How do I remove it? – MrEduar Mar 29 '21 at 04:08
  • 4
    You may try `sudo apt-get remove php-xml` @MrEduar – Player1 Mar 29 '21 at 18:45
10

For CentOS, RHEL, Fedora:

$ yum search php-xml
============================================================================================================ N/S matched: php-xml ============================================================================================================
php-xml.x86_64 : A module for PHP applications which use XML
php-xmlrpc.x86_64 : A module for PHP applications which use the XML-RPC protocol
php-xmlseclibs.noarch : PHP library for XML Security
php54-php-xml.x86_64 : A module for PHP applications which use XML
php54-php-xmlrpc.x86_64 : A module for PHP applications which use the XML-RPC protocol
php55-php-xml.x86_64 : A module for PHP applications which use XML
php55-php-xmlrpc.x86_64 : A module for PHP applications which use the XML-RPC protocol
php56-php-xml.x86_64 : A module for PHP applications which use XML
php56-php-xmlrpc.x86_64 : A module for PHP applications which use the XML-RPC protocol
php70-php-xml.x86_64 : A module for PHP applications which use XML
php70-php-xmlrpc.x86_64 : A module for PHP applications which use the XML-RPC protocol
php71-php-xml.x86_64 : A module for PHP applications which use XML
php71-php-xmlrpc.x86_64 : A module for PHP applications which use the XML-RPC protocol
php72-php-xml.x86_64 : A module for PHP applications which use XML
php72-php-xmlrpc.x86_64 : A module for PHP applications which use the XML-RPC protocol
php73-php-xml.x86_64 : A module for PHP applications which use XML
php73-php-xmlrpc.x86_64 : A module for PHP applications which use the XML-RPC protocol

Then select the php-xml version matching your php version:

# php -v
PHP 7.2.11 (cli) (built: Oct 10 2018 10:00:29) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

# sudo yum install -y php72-php-xml.x86_64
Shoaib Khan
  • 899
  • 14
  • 26
-1

you need just update your local composer file:

  • first you need remove "composer.lock" file from you app

  • then, exec in your bash:

composer update --ignore-platform-req=ext-curl
  • so try again
composer require cviebrock/eloquent-sluggable
IsraelCena
  • 29
  • 1
  • 6