How to check php extension is enabled

To check if a specific PHP extension is enabled, you can use any of the following methods:

1. Using the php -m Command

Run the following command in your terminal or command prompt:


php -m

This lists all enabled PHP extensions. Search for your desired extension (e.g., pdo, mbstring, etc.) in the output.

2. Using phpinfo() Function

Create a PHP file, for example, info.php, with the following content:


phpinfo();

Access this file in your browser (e.g., http://localhost/info.php). Look for the desired extension under the “Modules” or “Additional Modules” sections.

3. Using extension_loaded() Function

Run a script to programmatically check if the extension is loaded:

$extension = 'mbstring'; // Replace with your desired extension name
if (extension_loaded($extension)) {
echo '$extension is enabled.';
} else {
echo '$extension is not enabled.';
}

4. Using ini_get()

Some extensions have specific directives in php.ini. Check if the directive is set:

if (ini_get('extension_name')) {
echo 'Extension is enabled.';
} else {
echo 'Extension is not enabled.';
}

Replace extension_name with the relevant setting, like mbstring.

5. Check php.ini

Manually inspect the php.ini file for the extension:

Look for lines like extension=extension_name.so (Linux/Mac) or extension=extension_name.dll (Windows).

Ensure the line is uncommented.

These methods help confirm whether a PHP extension is enabled in your environment.

Leave a Reply

Your email address will not be published. Required fields are marked *


Follow by Email
YouTube
YouTube
LinkedIn
Share
Instagram