How to check which PHP extensions have been enabled/disabled in Ubuntu Linux 12.04 LTS
On Ubuntu 12.04 LTS, the package manager and the PHP build system often leave you guessing about the state of your runtime environment. You might see php-xml installed in /var/lib/dpkg/status, yet your application still throws "Class 'XMLReader' not found" errors. This discrepancy happens because an extension can be compiled into the core or dynamically loaded, but it isn't necessarily active in the current PHP process. Before attempting to install new modules like php_zip, php_xml, or php_gd2, you must first verify exactly what is currently enabled.
The most reliable way to check this without relying on external documentation is to query the PHP runtime directly. The standard approach involves running the PHP CLI with a flag that dumps the configuration of loaded modules. Execute the following command in your terminal:
php -m
This command prints a list of all compiled and dynamically loaded extensions available to the current PHP binary. If you see zip, xml, or gd in the output, they are active. If they are missing, the corresponding .so files might be absent from your extension_dir, or the extension is explicitly disabled in your configuration file.
To get a more granular view, inspect the output of php -i. This command displays all configuration directives and their current values. Look for the "Loaded Modules" section at the top of the output. It provides a similar list to php -m but also includes memory limits and other core settings. However, php -m remains the preferred method for extension auditing because it is concise and less prone to parsing errors in scripts that consume this data programmatically.
Sometimes, an extension appears in your installed packages but fails to load due to missing dependencies or version mismatches between PHP and the library (e.g., libxml2). In these cases, php -m will not list the extension, even if the package is marked as "installed" by APT. This is a common pitfall when managing LAMP stacks on older Ubuntu versions where dependency resolution was less robust than modern distributions.
If you need to check the status of extensions defined in configuration files rather than what is currently loaded, examine the php.ini file located in the web server's configuration directory. On Ubuntu 12.04, this is typically found at /etc/php5/apache2/php.ini for Apache or /etc/php5/cli/php.ini for the command-line interface. Search these files for lines starting with extension=. You will encounter three states:
- Enabled: The line reads
extension=php_zip.so(or similar) without a leading semicolon. - Disabled but loadable: The line is commented out with a semicolon, e.g.,
;extension=php_zip.so. This means the extension exists and can be loaded if uncommented, but it is not active by default. - Explicitly disabled: The directive might use the
-prefix in newer PHP versions, though on 5.4/5.6 (the versions supported on 12.04), comments are the standard way to disable dynamic extensions.
It is crucial to distinguish between these states. A commented-out extension does not mean it isn't installed; it simply means the runtime ignores it until you change the configuration. To be absolutely certain an extension is inactive, combine the file inspection with the php -m output. If the line exists in php.ini but is absent from the php -m list, then either the .so file is missing or there is a syntax error preventing the config file from loading entirely.
When moving forward to enable specific extensions like php_gd2, ensure you understand that enabling them modifies the behavior of your application immediately. There is no "safe mode" for PHP extensions; once enabled, they consume memory and add overhead to every request. If an extension causes a segfault or hangs your script, disabling it in php.ini requires restarting the web server to take effect.
For developers managing production environments, relying solely on visual inspection of php -m is insufficient. Automate this check within your deployment scripts. You can parse the output of php -m using tools like grep or regular expressions to script your validation logic before rolling out code changes that depend on specific extensions.
If you require further guidance on managing PHP configurations, scaling your stack, or integrating these components with modern frameworks, resources from https://laravelcompany.com can provide additional context on application architecture and deployment strategies. However, for low-level system administration tasks like verifying Ubuntu 12.04 extensions, direct interaction with the CLI remains the most effective tool.