I'm trying to run a php script on a lamp server in google cloud. The script is failing because of an uncaught error, despite SimpleXML and xml being installed and active (as far as I can tell). Having just moved to Google Cloud, I'm not familiar enough with the environment, and don't know if I'm missing some basic setup steps. I have wordpress running set up and running successfully on the same server, so I'm a bit baffled by this. Would appreciate any help or direction!
PHP 8.2.8 on Ubuntu 20.04.6 LTS.
I'm getting this error whenever I try to use SimpleXMLElement.
Fatal error: Uncaught Error: Class "SimpleXMLElement" not found in /var/www/html/ifg_indexp/tpnapis/simplexmltest.php:48
I thought maybe the function was not installed/enabled, but it seems to be :
$ php -m | grep SimpleXML
SimpleXML
$ php -m | grep xml
libxml
xml
xmlreader
xmlrpc
xmlwriter
php -i returns that the module is enabled, so that seems ok too.
$ php -i
SimpleXML
SimpleXML support => enabled
Schema support => enabled
Also xml is showing as active :
xml
XML Support => active
XML Namespace Support => active
libxml2 Version => 2.9.14
The simplified file I'm trying to test with is as follows :
<?php
use SimpleXMLElement;
//use SimpleXML;
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$note = <<<XML
<depots>
<depot>
<number>001</number>
<phone>111</phone>
<name>company1</name>
<depotaddress>
<add1>address line1</add1>
<add2>address 2</add2>
</depotaddress>
</depot>
<depot>
<number>002</number>
<phone>222</phone>
<name>company2</name>
<depotaddress>
<add1>address1</add1>
<add2>address2</add2>
</depotaddress>
</depot>
</depots>
XML;
echo "</br>printf : ";printf($note);
echo "</br>var_dump : ";var_dump($note);
echo "</br>asXML :";
$xml = new SimpleXMLElement($note);
echo $xml;
echo $xml->asXML();
?>
That gives me this result on screen :
printf : 001 111 company1 address line1 address 2 002 222 company2 address1 address2
var_dump : string(364) " 001 111 company1 address line1 address 2 002 222 company2 address1 address2 "
asXML :
Fatal error: Uncaught Error: Class "SimpleXMLElement" not found in /var/www/html/xxx1/xxx2/simplexmltest.php:40 Stack trace: #0 {main} thrown in /var/www/html/xxx1/xxx2/simplexmltest.php on line 40
The only other things that seem odd to me is that the PHP version on phpinfo() is different to the version on cli.
Also, there is no SimpleXML details box on the phpinfo() screen.