Question
I am using EasyPHP and need to enable the pdo_mysql extension. I uncommented this line in a php.ini file:
extension=php_pdo_mysql.dll
However, the problem remains. Because I am running PHP from the command line, I suspect that the CLI may be using a different php.ini file. How can I find the php.ini file that the PHP CLI actually uses?
Short Answer
PHP can run under different environments, such as a web server and the command line. Each environment may load a different configuration file. You will learn how to identify the exact PHP executable used by your terminal, locate its loaded php.ini, verify that an extension is enabled, and diagnose common configuration problems.
Concept
PHP configuration is controlled primarily by an INI file, usually named php.ini. It contains settings such as error reporting, timezone, memory limits, and enabled extensions.
The important detail is that the PHP CLI and your web server are separate PHP runtime environments. For example:
- Your terminal may execute one
php.exefromPATH. - EasyPHP's Apache server may use a different
php.exeand a differentphp.ini. - A command can also load additional
.inifiles from a configuration scan directory.
Editing a php.ini file only changes PHP if it is the file loaded by the PHP executable you are actually running. Therefore, first identify the CLI executable and its configuration, then enable the extension there.
For pdo_mysql, PHP must be able to find and load the extension file. On Windows installations, this is often a DLL such as php_pdo_mysql.dll in PHP's ext directory.
Mental Model
Think of each PHP environment as a separate kitchen.
- The PHP executable is the chef.
- The
php.inifile is the chef's recipe book. - PHP extensions such as
pdo_mysqlare tools in the kitchen.
You may edit a recipe book in one kitchen (for example, EasyPHP's web-server PHP), while your terminal is using a chef in another kitchen with a different recipe book. php --ini asks the current command-line chef which recipe book it opened.
Syntax and Examples
Use the following command in the same terminal where you run your PHP scripts:
php --ini
Typical output looks similar to this:
Configuration File (php.ini) Path: C:\EasyPHP\php
Loaded Configuration File: C:\EasyPHP\php\php.ini
Scan for additional .ini files in: C:\EasyPHP\php\conf.d
Additional .ini files parsed: C:\EasyPHP\php\conf.d\custom.ini
The most useful line is:
Loaded Configuration File: C:\EasyPHP\php\php.ini
That is the main php.ini used by the CLI.
To see which PHP executable your shell runs, use this on Windows:
where php
Example:
C:\EasyPHP\php\php.exe
C:\Program Files\PHP\php.exe
If more than one path appears, the first one is normally the executable selected through PATH.
To check whether pdo_mysql is loaded:
php -m
Look for both of these module names:
PDO
pdo_mysql
You can also inspect the exact configuration values:
Step by Step Execution
Suppose you run this command:
php --ini
And receive:
Configuration File (php.ini) Path: C:\EasyPHP\php
Loaded Configuration File: C:\EasyPHP\php\php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed: (none)
Follow this sequence:
-
phpis resolved by your terminal to a particularphp.exe. -
That executable searches for configuration according to its startup rules.
-
PHP reports
C:\EasyPHP\php\php.inias the loaded configuration file. -
Open that exact file.
-
Ensure the extension line is enabled:
extension=php_pdo_mysql.dll -
Save the file.
-
Start a new terminal, then run:
php -m | findstr /I pdo_mysql -
If
pdo_mysqlappears, the CLI successfully loaded the extension.
The CLI reads its configuration each time a new PHP process starts. Unlike Apache or PHP-FPM, it usually does not need a service restart; opening a new terminal or running the command again is sufficient.
Real World Use Cases
- Running database migrations: Framework migration commands need
pdo_mysqlto connect to MySQL from the terminal. - Composer scripts: A Composer command may invoke PHP CLI, so required extensions must be enabled for the CLI installation.
- Scheduled tasks: Cron jobs or Windows Task Scheduler jobs use CLI PHP and may fail if their required extensions are missing.
- Debugging environment differences: A website may work through Apache while a command such as
php artisan migratefails because each uses different PHP configuration. - Build and deployment scripts: CI pipelines often run
php, and checkingphp --inimakes configuration failures reproducible.
Real Codebase Usage
Developers commonly add environment diagnostics before changing settings:
where php
php --version
php --ini
php -m
This establishes four facts:
- Which executable is running.
- Which PHP version it is.
- Which main configuration file it loaded.
- Which extensions are available.
For an application that needs MySQL through PDO, a practical validation command is:
php -r "var_dump(extension_loaded('pdo_mysql'));"
Expected output:
bool(true)
In projects, configuration issues are often handled with a fail-fast check. For example, a setup script can stop with a clear message when an extension is absent:
<?php
if (!extension_loaded('pdo_mysql')) {
fwrite(STDERR, "The pdo_mysql extension is required. Run php --ini to find the active configuration.\n");
exit(1);
}
echo "pdo_mysql is available.\n";
This is more helpful than allowing a later database connection to fail with a vague driver error.
Common Mistakes
Editing the wrong php.ini
It is common to edit the php.ini found in a web-server folder while the terminal executes another PHP installation.
Avoid this by running:
php --ini
where php
Assuming php.ini-development or php.ini-production is active
PHP distributions may contain template files named php.ini-development and php.ini-production. They are not necessarily loaded.
Check Loaded Configuration File rather than editing a file based only on its name.
Leaving a semicolon at the beginning
A semicolon comments out an INI directive:
; extension=php_pdo_mysql.dll
This does not load the extension. Remove the semicolon:
extension=php_pdo_mysql.dll
Using an incorrect extension_dir
PHP must be able to locate php_pdo_mysql.dll. If the extension directory is wrong, PHP may show a startup warning.
Comparisons
| Command or tool | What it tells you | Best use |
|---|---|---|
php --ini | Loaded php.ini, scan directory, and additional INI files | Finding the CLI configuration source |
where php on Windows | All matching php.exe files on PATH | Detecting multiple PHP installations |
php -v | PHP version and startup warnings | Quickly spotting extension load errors |
php -m | Loaded PHP module names | Confirming pdo_mysql is enabled |
php -i | Detailed PHP runtime configuration |
Cheat Sheet
:: Show the main php.ini and additional parsed INI files
php --ini
:: Show which PHP executable(s) Windows can find
where php
:: Show PHP version and extension startup warnings
php -v
:: List loaded modules
php -m
:: Check one extension specifically
php -m | findstr /I pdo_mysql
:: Display detailed runtime configuration
php -i
:: Check whether an extension is loaded
php -r "var_dump(extension_loaded('pdo_mysql'));"
Relevant php.ini directives:
extension_dir = "ext"
extension=php_pdo_mysql.dll
Key rules:
- Trust
Loaded Configuration File, not a guessed file path. - A leading
;disables an INI line. - The CLI and web server can use different PHP versions and different INI files.
- Check
php -vafter edits to catch DLL loading warnings. - Confirm success with
php -morextension_loaded('pdo_mysql').
FAQ
How do I find the php.ini used by PHP CLI?
Run:
php --ini
Read the Loaded Configuration File line.
Why does php --ini say Loaded Configuration File: (none)?
The CLI did not load a main php.ini. Check the reported configuration path, create or copy an appropriate php.ini there if required by your installation, and run the command again.
How can I tell whether I have multiple PHP installations on Windows?
Run:
where php
If it shows multiple paths, verify which one is selected first and inspect it with php --ini.
Do I need to restart my computer after editing the CLI php.ini?
No. Each CLI PHP command starts a new PHP process and reads configuration again. Run php -m or your script after saving the file.
How do I confirm that pdo_mysql is enabled?
Run:
php -m | findstr /I pdo_mysql
Or run:
Mini Project
Description
Create a small PHP command-line diagnostic script that reports the active configuration file and checks whether the PDO and pdo_mysql extensions are available. This mirrors the first checks developers perform when a CLI database command cannot connect to MySQL.
Goal
Run one command that clearly reports whether the current PHP CLI is ready to use PDO with MySQL.
Requirements
Create a PHP file named check_mysql_driver.php.
Display the PHP binary path and loaded php.ini path.
Check both PDO and pdo_mysql with extension_loaded().
Exit with a non-zero status code if pdo_mysql is unavailable.
Print a helpful next step when the driver is missing.
Keep learning
Related questions
Are PDO Prepared Statements Enough to Prevent SQL Injection in PHP?
Learn how PDO prepared statements prevent SQL injection in PHP, what they protect, and the mistakes that still leave MySQL apps vulnerable.
Can You Bind an Array to an IN Clause in PHP PDO?
Learn how PDO handles placeholders in IN() clauses, why arrays cannot be bound directly, and the safe PHP pattern to build dynamic queries.
Choosing the Right MySQL Collation for PHP and UTF-8
Learn how MySQL character sets and collations work with PHP, and how to choose a practical UTF-8 setup for web applications.