82

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
user101289
  • 9,888
  • 15
  • 81
  • 148
  • 4
    From your screen capture of your `phpinfo()` page, it looks like SimpleXML is only in the "Module Authors" section. Which is only telling you who wrote it; that doesn't mean it's installed or loaded. In fact, if that's the only place it appears in `phpinfo()`, I suspect that means it is **not** installed. – Brendan White Feb 10 '17 at 21:06
  • $ php -i | grep simplexml – Ravshan Abdulaev Sep 13 '17 at 22:33
  • 5
    Try restarting php-fpm. sudo systemctl restart php-fpm – phpd Oct 18 '18 at 07:19
  • 1
    can you try my answer at https://stackoverflow.com/questions/49447168/call-to-undefined-function-simplexml-load-file/57025620#57025620 – Apit John Ismail Jul 14 '19 at 08:10

13 Answers13

101

I had the same problem and I'm using Ubuntu 15.10.

In my case, to solve this issue, I installed the package php7.0-xml using the Synaptic package manager, which include SimpleXml. So, after restart my Apache server, my problem was solved. This package came in the Debian version and you can find it here: https://packages.debian.org/sid/php7.0-xml.

Tieme
  • 62,602
  • 20
  • 102
  • 156
Alexandre Barbosa
  • 1,194
  • 1
  • 7
  • 6
  • 1
    @Alexandre Wohoo got OwnCloud working again with that, perfect! – Flatron Feb 24 '16 at 22:31
  • 45
    Ubuntu 16.04: sudo apt-get install php-xml – Sasha MaximAL Apr 25 '16 at 08:59
  • 2
    It seems the issue is also present in Ubuntu Server 16.04. After a clean install I encountered the issue. "PHP Fatal error: Uncaught Error: Call to undefined function xml_parser_create()" was being output to the PHP error log. Installing the package recommended by Alexandre fixed it. – MikeyE Jul 05 '16 at 19:33
  • The package is no longer available. Does someone know where if there is another source? – Mark Odey Nov 19 '19 at 04:16
  • @MarkOdey I had 404 not found, but then tried solution below from Flatron and it worked. Try 'apt update' – Martin Nov 26 '19 at 10:21
  • @Martin what version are you using? Ubuntu 15? I had similar issues on multiple occasion and what I have discovered is that it is easier to upgrade your OS to something to day than to find the right repo containing the library set you need. – Mark Odey Nov 26 '19 at 15:07
  • @Mark Odey Ubuntu 16 inside docker container – Martin Nov 26 '19 at 20:32
  • @Martin well that is borderline but may make sense. https://ubuntustudio.org/2019/04/ubuntu-studio-16-04-lts-reaches-end-of-life-eol/ Ubuntu 16 just reach it end of life and ondrej specifically said that they would not maintain repos for OS that reached its end of life. Anyways I faced that issue many times in the past and found that it ends up being more work digging for the required libraries than just updating to the latest lts and using ondrej ppa. (Sorry for spamming) Regardless this answer won't help anybody with Ubuntu 15. – Mark Odey Nov 26 '19 at 21:11
72

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 Ondřej's PHP ppa for almost two years now and it's working like charm)

Flatron
  • 1,375
  • 2
  • 12
  • 33
30

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.

Deepak R
  • 423
  • 8
  • 9
18

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.

brismuth
  • 36,149
  • 3
  • 34
  • 37
  • Thanks, this worked for me today! Can confirm this works on Alpine Linux 3.6.2 (Linux kernel 4.4.0-96-generic x86_64) – eluong Nov 08 '17 at 20:50
  • 1
    It's important to make sure that after you install the package on the Alpine container, you should run `docker restart ` to make these changes work. – guychouk Dec 20 '17 at 15:31
  • didnt worked for me...using alpine3.7 in docker...getting php7-simplexml (missing): required by: world[php7-simplexml] – ronit Mar 06 '18 at 07:11
  • 1
    @ronit try `apk add --no-cache php7-simplexml`. You need the `--no-cache` flag if you aren't running `apk update` first. – brismuth Mar 06 '18 at 18:22
  • `apk add --no-cache php7-simplexml` don't works on **php:7.4-fpm-alpine** – JRichardsz Jul 06 '22 at 20:08
13

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
WebLuke
  • 156
  • 1
  • 5
10

------------------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
Community
  • 1
  • 1
terwxqian
  • 591
  • 6
  • 7
  • 1
    This is a good answer because the `yum provides` command will help the user find the correct package for any version of PHP that is installed. It is not necessary to use the full package name in the `yum install` command. – Craig Finch Jun 30 '18 at 19:21
9

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
RustyNox
  • 409
  • 6
  • 7
  • thank you! this worked for me on NGINX!! just have to do: sudo apt install php7.3-xml (7.3 is my php version) and then restar services: sudo service nginx restart – Alejo_Blue Aug 04 '20 at 17:33
6

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
BlueP
  • 517
  • 7
  • 8
4

For Ubuntu 18.04 and php7.3, install php7.3-xml

    sudo apt-get install php7.3-xml

this will installl the required simplexml

redspidermkv
  • 503
  • 10
  • 25
Pankaj Bhagat
  • 197
  • 3
  • 7
3

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.

Mike Brant
  • 70,514
  • 10
  • 99
  • 103
  • @Mike-- thanks, that is true-- however, the module should be enabled by default. As far as I know, I'd need to recompile PHP to enable the module, since you can't enable it in php.ini. – user101289 Feb 24 '16 at 05:21
2
  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
Sahil Kashyap
  • 329
  • 2
  • 10
-1

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

elfTine
  • 299
  • 2
  • 5
-1

in my case, you have to make sure about your php version.

php -v

example: if your php is PHP 7.4.28, than you have to write

sudo apt install php7.4-xml

see, instead to write all version, just write the first and second, than following with -xml

I have this issue and it's take time, until I understand how to write properly. hopefully it's work for you

ahm
  • 107
  • 2
  • 9