Call to undefined function simplexml_load_file()

Call to undefined function simplexml_load_file()

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Call to undefined function simplexml_load_file()

When your PHP error log screams "Call to undefined function simplexml_load_file()", it is often disorienting because the SimpleXML module is clearly listed in the output of your php -m command. The discrepancy between a loaded extension and an undefined function usually points to a specific environment misconfiguration rather than a missing installation.

In the scenario described, PHP 7.0 is running on an Ubuntu server. The module list confirms that SimpleXML is present alongside libxml, xmlreader, and dom. However, the fatal error occurs at runtime. This indicates that while the extension was compiled into or loaded by the system's core PHP process, the specific SAPI (Server API) handling your web requests—likely Apache or Nginx via PHP-FPM—is not seeing that same configuration.

The most frequent culprit is a mismatch between the CLI and the web server environments. On Linux distributions like Ubuntu, it is common to have multiple PHP versions installed simultaneously (e.g., 7.0 for legacy sites and 8.x as the default). If you upgraded your system or switched package managers without careful migration, your php.ini file used by the CLI might differ from the one serving web requests.

To diagnose this, you must inspect the configuration active during the web request. Run the following command to see exactly which config file is being utilized:

php -i | grep "Configuration File"

Compare the path shown here against the php.ini file you are editing in your text editor. If they do not match, changes made to one file will be ignored by the web server, leading to the exact error you are facing.

If the configuration paths align, the issue may lie in how the extension is loaded. In PHP 5.x and early 7.x versions, SimpleXML was often a built-in component rather than a separate .so file. However, on some stripped-down distributions or custom builds, it might be explicitly disabled via disable_functions in the php.ini. Check for this line:

disable_functions=...simplexml_load_file...

While rare, administrators sometimes add entire XML handling functions to a blacklist to mitigate certain security vulnerabilities. If you find simplexml_load_file listed there, remove it or comment out that specific line.

Another possibility involves the order of extension loading. Although less common in PHP 7.0, some setups require libxml.so to be explicitly loaded before SimpleXML functions can resolve correctly. Ensure that extension=php_simplexml.so (or simply SimpleXML depending on the distro) appears in the active configuration file after all necessary core libraries are initialized.

If you are using a specific framework like Laravel, ensure that your deployment script is not overriding global configurations with a local one that disables extensions. Sometimes, when copying a project to a new server, the php.ini defaults provided by the OS might be too minimal for the application's requirements.

In cases where the web server environment is heavily restricted or running on a minimal container image, it might be necessary to rebuild the PHP stack with SimpleXML explicitly enabled. For Ubuntu users, this often involves ensuring the php7.0-simplexml package is installed and that no conflicting packages are preventing the extension from loading:

apt-get install php7.0-simplexml

After making these changes, you must restart your web server (Apache or Nginx) or reload PHP-FPM to apply the new configuration. A simple service apache2 restart is rarely sufficient if the process manager isn't watching for config changes; using php-fpm7.0 -R ensures the daemon re-reads its configuration immediately.

If you are maintaining legacy applications on older PHP versions, remember that SimpleXML functionality was robust in 7.0 but has evolved significantly since then. If you are considering an upgrade path, note that modern PHP versions treat these XML functions as integral parts of the core language rather than optional extensions, reducing the likelihood of such discrepancies.

Finally, if none of these steps resolve the issue, verify that your script is not accidentally running in a different context where SimpleXML is disabled. Check for any custom .htaccess rules or Nginx configurations that might be invoking a different PHP version via php_value directives. Ensuring consistency across CLI and SAPI environments remains the primary defense against this class of errors.

Our network