How to enable php extensions in ubuntu?

How to enable php extensions in ubuntu?

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

Stefan Bogdanescu

Founder & Senior Architect

Why Editing /etc/php/8.2/apache2/php.ini Doesn't Load Extensions on Ubuntu 22.04

Editing a configuration file is only half the battle when managing PHP extensions on Ubuntu. The specific scenario you described—uncommenting lines in /etc/php/8.2/apache2/php.ini, restarting Apache, and seeing no change—is a classic case of mismatched configuration sources. On modern Ubuntu distributions like 22.04 (Jammy), the package manager does not rely solely on the php.ini file you edit by hand to determine which extensions are loaded.

When you check your environment using phpinfo() or php -m, you are likely looking at a configuration that hasn't been touched, while your edits sit in a file that Apache isn't actually reading. This disconnect usually stems from one of two sources: the default PHP configuration provided by the system, or a separate, dynamic configuration file generated for specific modules.

The Default Configuration Trap

On Ubuntu 22.04, the PHP package installed via apt often defaults to using php.ini.default as the baseline. When you edit /etc/php/8.2/apache2/php.ini, you are modifying a drop-in configuration file intended to override settings in the default one. However, if the extension is not listed in the default file or if the directive is set to no there, simply uncommenting it in the override file might not be enough if the system expects a specific binary presence.

More critically, Ubuntu's PHP packages frequently separate configuration into multiple files rather than merging everything into a single monolithic php.ini. For instance, extensions like pdo_mysql, gd, or mbstring often have their own dedicated .ini files located in /etc/php/8.2/apache2/conf.d/. If you comment out the extension loading line in your main php.ini file, but fail to remove the corresponding line from a specific extension config file, the extension might load unexpectedly. Conversely, if you try to enable an extension by editing the main php.ini but the system is actually reading a configuration generated from a different source (like php8.2-fpm.conf.d-available for CLI contexts), your changes will have zero effect.

The Dynamic Configuration Mechanism

The most common reason for this behavior on Ubuntu is the presence of .conf files in the conf.d directory that take precedence or are loaded independently. When you run apache2 -M, you might see modules listed there, but they aren't necessarily tied to the lines you edited in php.ini.

To correctly enable an extension, you generally need to ensure two things:

  1. The PHP binary for the extension exists on the system. You can verify this by checking if the .so file exists in /usr/lib/php/20220829/. If the file is missing, editing php.ini will do nothing; you must install the package (e.g., pecl install <extension> or sudo apt install php8.2-<extension>).
  2. The extension is explicitly loaded in the active configuration tree.

How to Properly Enable Extensions

Instead of manually editing /etc/php/8.2/apache2/php.ini, the recommended approach on Ubuntu is to manage extensions via package management or by adding lines to the conf.d directory.

First, verify which PHP binary Apache is using:

php -i | grep "Loaded Configuration File"

If the output points to /etc/php/8.2/apache2/php.ini, proceed to check your extension list again. If the extension you need (for example, redis or imagick) is missing from the output of php -m, it means the binary isn't installed.

Install the missing extension package:

sudo apt update
sudo apt install php8.2-redis

After installation, check if Apache picks up the new module without further configuration changes:

sudo systemctl restart apache2
php -m | grep redis

If it still doesn't show up, you likely need to explicitly load the extension in a dedicated config file. Create or edit a file in /etc/php/8.2/apache2/conf.d/:

sudo nano /etc/php/8.2/apache2/conf.d/10-redis.ini

Inside this file, add:

extension=redis.so

Note that you do not need to touch the main php.ini for this to work; the files in conf.d are automatically included during initialization.

Verifying the Fix

Once you have installed the package and added the line to a .conf.d file, restart Apache:

sudo systemctl restart apache2

Now, run your PHP info script again. If the extension appears, the issue was simply that the extension wasn't installed in the system libraries or wasn't loaded via the standard conf.d mechanism.

If you are using a framework like Laravel for your web application, ensure that your local composer.json doesn't conflict with the system extensions, and remember that phpinfo() inside a Laravel app might be cached if you haven't cleared your view cache or session data after making changes to core PHP settings. However, in most Ubuntu setups, clearing the configuration via php -m is sufficient once the package and config files align correctly.

Our network