PHP Version and Extensions Required for SunSitemap: Complete Setup Guide

SunSitemap requires PHP 5.5 or newer with the SimpleXML extension enabled, and the zlib extension if you intend to generate gzip-compressed sitemaps.

The msbatal/php-sitemap-generator repository provides a lightweight PHP class for generating XML sitemaps. Understanding the specific PHP version and extensions required for SunSitemap ensures your server environment can handle both standard XML output and optional compression features without runtime errors.

Minimum PHP Version Requirements

SunSitemap explicitly requires PHP 5.5 or newer, as documented in the installation notes at README.md line 30. This minimum version requirement exists because the class utilizes type hints and language features introduced in PHP 5.5. Attempting to run the generator on older versions will result in fatal parsing errors due to incompatible syntax.

Required PHP Extensions

The SunSitemap class depends on two core PHP extensions. While both are typically included in standard PHP distributions, they must be explicitly enabled in your php.ini configuration.

SimpleXML Extension (Mandatory)

The SimpleXML extension is required for constructing the XML document structure. In SunSitemap.php at line 194, the createSitemap() method instantiates new SimpleXMLElement(...) to build the <urlset> and <sitemapindex> nodes. Without this extension, the class will throw a fatal error immediately upon attempting to generate the sitemap XML.

Zlib Extension (Optional for Compression)

The zlib extension is only required if you enable gzip compression by setting $createZip = true. When compression is active, the code utilizes gzopen(), gzwrite(), and gzclose() functions (referenced at line 245 in SunSitemap.php) to create .gz archives.

The constructor performs a runtime check at lines 43–52 to verify zlib availability. If the extension is missing and compression is requested, the class throws an exception with the message: 'The GZip file compression module is not enabled.'

Environment Verification Script

Before deploying SunSitemap, verify your environment meets these requirements using the following diagnostic script:

<?php
// Verify PHP version and required extensions
if (version_compare(PHP_VERSION, '5.5.0', '<')) {
    die('SunSitemap requires PHP 5.5 or newer. Current version: ' . PHP_VERSION);
}

if (!extension_loaded('simplexml')) {
    die('SimpleXML extension is required but not loaded.');
}

if (!extension_loaded('zlib')) {
    echo 'Warning: Zlib extension not loaded. Gzip compression will be unavailable.';
} else {
    echo 'Environment check passed. Ready to generate sitemaps.';
}
?>

Configuration Examples

The following examples demonstrate usage with and without the optional gzip compression. Both require the SimpleXML extension, while only the second requires zlib.

Standard XML Sitemap (No Compression):

<?php
require_once 'SunSitemap.php';

$sitemap = new SunSitemap('https://example.com/', 'sitemap/');
$sitemap->addUrl('index.php', date('c'), 'daily', '1.0');
$sitemap->createSitemap()->updateRobots();
?>

Gzip-Compressed Sitemap (Requires Zlib):

<?php
require_once 'SunSitemap.php';

// Fourth parameter enables gzip compression
$sitemap = new SunSitemap('https://example.com/', 'sitemap/', null, true);
$sitemap->addUrl('about.php', date('c'), 'weekly', '0.8');
$sitemap->createSitemap()->updateRobots();
?>

Summary

  • PHP 5.5+ is mandatory according to the README.md at line 30.
  • SimpleXML is required for all operations to support the SimpleXMLElement instantiation at line 194 of SunSitemap.php.
  • Zlib is only required for gzip compression features utilizing gzopen() at line 245.
  • Runtime checks at lines 43–52 prevent silent failures when zlib is missing.
  • Both extensions must be enabled in php.ini despite being standard PHP components.

Frequently Asked Questions

Does SunSitemap work with PHP 8.x?

Yes. As implemented in msbatal/php-sitemap-generator, the PHP 5.5+ requirement means all modern PHP versions including PHP 8.0, 8.1, 8.2, and 8.3 are fully supported. The class uses stable language features that remain unchanged in newer releases.

How do I check if SimpleXML is enabled on my server?

Run extension_loaded('simplexml') in a PHP script or check your phpinfo() output. Alternatively, attempt to instantiate new SimpleXMLElement('<test/>')—a fatal error indicates the extension is missing. Most hosting providers enable SimpleXML by default.

What happens if I enable gzip compression without the zlib extension?

The constructor in SunSitemap.php lines 43–52 checks for function_exists('ob_gzhandler') and ini_get('zlib.output_compression'). If zlib is unavailable and you set $createZip = true, the class throws an exception: 'The GZip file compression module is not enabled.'

Can I generate sitemaps without shell access to check extensions?

Yes. Upload the verification script provided in the environment verification section to your web root and access it via browser. It will report your PHP version and extension status without requiring command-line access.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →