[php] PHP 7 simpleXML

I'm testing PHP7, and have a weird issue after a recent update. SimpleXML should be enabled by default, and my phpinfo page shows that it is available:

enter image description here

However, the functions are not available:

<?php

if (function_exists('simplexml_load_file')) {
    echo "simpleXML functions are available.<br />\n";
} else {
    echo "simpleXML functions are not available.<br />\n";
}

// result-- NOT available

And the module isn't listed as loaded:

~ $ php -m
[PHP Modules]
calendar
Core
ctype
curl
...
Reflection
session
shmop
sockets
SPL
standard
sysvmsg
sysvsem
sysvshm
tokenizer
Zend OPcache
zlib

Anyone know if there's a workaround for this?

Version info:

~ $ php -v
PHP 7.0.3-8+deb.sury.org~trusty+2 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies

This question is related to php simplexml php-7

The answer is


Typically on Debian systems you have different PHP configuration for CLI and for PHP running as say an Apache module. Your phpinfo page may very well show simplexml as being enabled via web server, while it is not enabled via CLI.


For Alpine (in docker), you can use apk add php7-simplexml.

If that doesn't work for you, you can run apk add --no-cache php7-simplexml. This is in case you aren't updating the package index first.


For all those using Ubuntu with ppa:ondrej/php PPA this will fix the problem:

apt install php7.0-mbstring php7.0-zip php7.0-xml

(see https://launchpad.net/~ondrej/+archive/ubuntu/php)

Thanks @Alexandre Barbosa for pointing this out!

EDIT 20160423:

One-liner to fix this issue:

sudo add-apt-repository -y ppa:ondrej/php && sudo apt update && sudo apt install -y php7.0-mbstring php7.0-zip php7.0-xml

(this will add the ppa noted above and will also make sure you always have the latest php. We use Ondrej's PHP ppa for almost two years now and it's working like charm)


  1. Use php -v //PHP 8.0.1

  2. Check the latest version of simple xml here

https://pkgs.org/download/php-simplexml

  1. Mine was version 8 so
sudo apt-get install php8.0-xml

Because Google led me here, on Ubuntu 20.04 this works in 2020:

sudo apt install php7.4-xml

If on Apache2, remember to restart (probably not necessary):

sudo systemctl restart apache2

For Ubuntu 14.04 with

PHP 7.0.13-1+deb.sury.org~trusty+1 (cli) ( NTS )

sudo apt-get install php-xml

worked for me.


------------------in centos-------------------------

find out which package provides php-xml:

 yum provides php-xml

then from the output list,select the appropriate one, install

yum install php70u-xml-7.0.14-2.ius.centos7.x86_64

For Ubuntu 18.04 and php7.3, install php7.3-xml sudo apt-get install php7.3-xml

this will installl the required simplexml


I'm using Bash on Windows (Ubuntu 16.04) and I just installed with php7.0-xml and all is working now for the Symfony 3.2.7 PHP requirements.

sudo apt-get install php7.0-xml

my experience

  1. get your php version

    php --version

  2. Instal package for your php version

    sudo apt-get install php7.4-xml

  3. Restart apache

    sudo systemctl reload apache2


Had the same problem on AWS Linux 2, phpinfo() shows SimpleXML installed but not working, below cmd solved my issue

sudo yum install php-xml

Examples related to php

I am receiving warning in Facebook Application using PHP SDK Pass PDO prepared statement to variables Parse error: syntax error, unexpected [ Preg_match backtrack error Removing "http://" from a string How do I hide the PHP explode delimiter from submitted form results? Problems with installation of Google App Engine SDK for php in OS X Laravel 4 with Sentry 2 add user to a group on Registration php & mysql query not echoing in html with tags? How do I show a message in the foreach loop?

Examples related to simplexml

PHP 7 simpleXML 'xmlParseEntityRef: no name' warnings while loading xml into a php file SimpleXml to string Get value from SimpleXMLElement Object Error: "Input is not proper UTF-8, indicate encoding !" using PHP's simplexml_load_string How to use XMLReader in PHP? Accessing @attribute from SimpleXML How to convert array to SimpleXML Remove a child with a specific attribute, in SimpleXML for PHP Using SimpleXML to create an XML object from scratch

Examples related to php-7

PHP7 : install ext-dom issue mcrypt is deprecated, what is the alternative? PHP executable not found. Install PHP 7 and add it to your PATH or set the php.executablePath setting PHP 7 simpleXML How can I enable the MySQLi extension in PHP 7? PHP ternary operator vs null coalescing operator "Call to undefined function mysql_connect()" after upgrade to php-7 How do I install the ext-curl extension with PHP 7? PHP 7 RC3: How to install missing MySQL PDO PHP 7: Missing VCRUNTIME140.dll