PHP7:安装ext-dom问题


168

我在使用PHP7的Ubuntu 16.04服务器上运行laravel 5.4。尝试安装cviebrock/eloquent-sluggable软件包会引发一些错误:

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.

我在应用程序的本地版本上安装此软件包没有问题。

Answers:


363

首先,请阅读警告!它说,你跑作曲家!其次,您可能在本地使用Xammp,默认情况下具有所需的php库。

但是在您的服务器中,您不见了ext-domphp-xml拥有您需要的所有相关软件包。因此,您只需运行以下命令即可安装它:

sudo apt-get update
sudo apt install php-xml

您很可能也失踪mbstring了。如果收到错误,请同时安装此软件包:

sudo apt-get install php-mbstring

然后运行:

composer update
composer require cviebrock/eloquent-sluggable

谢谢 。如果我不使用sudo运行作曲家,则会收到此错误:Could not read /home/pish/.composer/auth.json file_get_contents(/home/pish/.composer/auth.json): failed to open stream: Permission denied
amin

4
搜索chmod和chown命令是一个权限问题。更改此文件夹的权限和所有者,就可以了。
Anar Bayramov

@rodrane您的代码中有一个错字用于安装php-mbstring软件包,应该是sudo apt-get。除此之外; 它就像一个魅力。谢谢!
罗宾B

我在机器上安装了php7.0-xml,但是当我执行以下操作时,作曲家仍然会向我抛出此错误composer install
Salustiano Muniz

@SalustianoMuniz您可能必须启用PHP中的模块。例如,sudo phpenmod xmlxmlreader&使用和做相同的事情xmlwriter。然后重新启动服务器(如果是apache:),sudo service apache2 restart然后尝试重新安装。
蒂姆·维西(TimVisée)

112

对于想要在php 7.1上安装ext-dom的用户,请运行以下命令:

sudo apt install php-xml

5
这在Ubuntu 18.04上对我有用-迄今为止最好的答案。
拂尘

这个答案的问题是它使用当前设置的默认php版本。例如说我sudo update-alternatives --set php /usr/bin/php7.0php-xml会下载php7.0-xml。使用这种方法时要谨慎,我总是建议更换@anar的做法
:曹淑红

但是该示例清楚地表明OP要求的是7.0版本,但未遵循所选答案。这是异常现象。不过,了解版本确实有意义。
gkephorus

4

对于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

然后选择与您的php版本匹配的php-xml版本:

# 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

3

sudo apt install php-xml 可以使用,但问题是它将下载最新PHP版本的插件。

如果您的PHP版本不是最新的,则可以在其中添加版本:

# 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 (latest)
sudo apt install php-xml

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.