A working PHP setup has three separate concerns: the PHP runtime, an optional web server integration, and the configuration loaded by that execution mode. Confirm each one instead of assuming that a successful installer configured every terminal and server process.
After this lesson, you can identify the PHP executable in use, find its loaded configuration, enable a required extension, and explain why a script may work in the terminal but fail through Apache or PHP-FPM.
Use a maintained operating-system package, the official Windows build, a development bundle such as XAMPP, or a container. Choose one primary setup for a project so that the terminal, editor, tests, and web server agree on the PHP version.
| Setup | Best Fit | Check |
|---|---|---|
| XAMPP or similar bundle | Fast local web setup | Confirm the bundled php.exe and Apache module |
| Operating-system package | Native Linux or macOS workflow | Confirm package version and enabled extensions |
| Container | Reproducible team environment | Pin the image version and build configuration |
Run these commands in the same terminal used for Composer and tests. On Windows with XAMPP, call C:\xampp\php\php.exe explicitly when php is not on PATH.
php --version
php --ini
php -m
--version identifies the executable version, --ini lists loaded configuration files, and -m lists available modules.
PHP reads php.ini when the runtime starts. A web server process can load a different file from the CLI, so compare php --ini with phpinfo() or php_ini_loaded_file() in the web request before changing settings.
Restart a long-running web server or PHP-FPM process after changing startup configuration. A new CLI command starts a new process and therefore reads its configuration again automatically.
<?php
echo 'PHP: ' . PHP_VERSION . PHP_EOL;
echo 'SAPI: ' . PHP_SAPI . PHP_EOL;
echo 'php.ini: ' . (php_ini_loaded_file() ?: 'not loaded') . PHP_EOL;
Remove this diagnostic page after setup because configuration output reveals server details.
Enable only extensions the application needs, using the package manager or the correct php.ini. Verify the result in the same SAPI that runs the application. PDO may be loaded while a driver such as pdo_mysql is still missing.
<?php
if (!extension_loaded('pdo_mysql')) {
throw new RuntimeException('The pdo_mysql extension is required.');
}
echo 'PDO MySQL ready';
PDO MySQL ready
The output assumes the driver is installed; otherwise the deliberate exception names the missing capability.
0 of 2 checked
Try this next
0 of 2 completed
Explore 500+ free tutorials across 20+ languages and frameworks.