PHP7:安装ext-dom问题

ale*_*lex 121 laravel composer-php php-7 laravel-5.4

我正在使用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.
Run Code Online (Sandbox Code Playgroud)

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

Ana*_*mov 279

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

但是在你的服务器中你错过了ext-dom.php7.1-xml拥有您需要的所有相关包.因此,您只需运行以下命令即可安装:

sudo apt-get update
sudo apt-get install php7.1-xml
Run Code Online (Sandbox Code Playgroud)

很可能你也错过mbstring了.如果您收到错误,请安装此软件包:

sudo apt-get install php-mbstring
Run Code Online (Sandbox Code Playgroud)

然后运行:

composer update
composer require cviebrock/eloquent-sluggable
Run Code Online (Sandbox Code Playgroud)

  • 它是一个权限问题搜索chmod和chown命令.更改此文件夹的权限和所有者您将没事. (4认同)
  • 谢谢 。如果我不使用 `sudo` 来运行 Composer,则会出现此错误:`无法读取 /home/pish/.composer/auth.json file_get_contents(/home/pish/.composer/auth.json): 无法打开流:权限被拒绝` (3认同)

Pay*_*jad 94

谁想要在php 7.2上安装ext-dom并运行以下命令:

sudo apt install php-xml
Run Code Online (Sandbox Code Playgroud)

  • 这对我使用Ubuntu 18.04 - 迄今为止最好的答案. (5认同)

Pla*_*er1 52

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
sudo apt install php7.4-xml

# PHP 8
sudo apt install php-xml
Run Code Online (Sandbox Code Playgroud)

  • 您可以尝试“sudo apt-get remove php-xml”@MrEduar (4认同)
  • 我正在运行 7.3,其他人说要安装“php-xml”,所以我安装了,但我仍然遇到完全相同的问题。一旦你看到它有多简单就很容易理解,但在看到这个答案之前我完全错过了它。安装 php7.3-xml 解决了我的问题。 (3认同)

Sho*_*han 9

对于 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
Run Code Online (Sandbox Code Playgroud)

然后选择与您的 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
Run Code Online (Sandbox Code Playgroud)


Dim*_*thu 5

简单地运行

sudo apt install php-xml
Run Code Online (Sandbox Code Playgroud)

它对我有用

  • 使用 Ubuntu 20.04 LTS ,这个唯一的命令解决了这个问题 (2认同)