Configuring PhpStorm for Local PHP, Composer Autoloading, and PHPUnit Execution
A task guide for pointing PhpStorm at a local PHP CLI binary, indexing Composer dependencies, and running PHPUnit from the editor gutter instead of the terminal.
29 May 2026, 02:01 UTC

Switching to a terminal just to run vendor/bin/phpunit interrupts debugging and scatters test output away from your editor. Configuring PhpStorm to execute PHPUnit directly from the editor gutter keeps stack traces, pass/fail counts, and breakpoints in one place. The practical outcome is a project where the IDE knows which PHP binary to use, resolves Composer dependencies, and launches tests without command-line detours.
Desired Outcome
After setup, your project should open in PhpStorm with three things working together: a configured local PHP CLI interpreter, Composer dependencies recognized and indexed, and PHPUnit tests runnable from the Run widget or the editor gutter. Failures should appear in a test results tree with clickable stack traces, not as opaque process errors.
Prerequisites
- A local PHP CLI executable that matches the PHP version required by the project. CLI means the command-line binary, not a web server module.
- Composer installed globally or available as a
.pharfile. - A
composer.jsonthat declaresphpunit/phpunitunderrequire-dev. - The project opened at its root directory in PhpStorm, not a subdirectory, so relative paths in
composer.jsonandphpunit.xmlresolve correctly.
Focused Procedure
Add a Local PHP CLI Interpreter
Open Settings/Preferences (on Windows/Linux press Ctrl+Alt+S; on macOS press Cmd+,). Navigate to the PHP page. Menu labels vary across PhpStorm releases, so if you do not see a PHP entry immediately, look under Languages & Frameworks.
Add a new CLI interpreter by pointing to your local PHP binary—for example, /usr/bin/php, /usr/local/bin/php, or C:\php\php.exe. PhpStorm reads the binary, detects the active php.ini file, and lists loaded extensions such as Xdebug. A CLI php.ini is not the same as a web server php.ini; debugger extensions often need separate enablement for CLI use.
Initialize Composer and Synchronize Dependencies
If composer.json exists at the project root, PhpStorm usually detects it and offers to initialize Composer support. Accept that prompt or configure it manually under the Composer settings page. Once Composer is recognized, open the built-in terminal and run:
composer install
Run this from the project root. No elevated permissions are required beyond write access to the project directory. The expected check is that a vendor/ directory appears and contains an autoload.php file. If the local PHP version is older than the php constraint in composer.json, Composer may fail dependency resolution or install packages that behave unexpectedly at runtime.
After installation, confirm that vendor/ is indexed and not marked as excluded in the project view. Excluded directories are skipped by code insight, which produces false undefined-class warnings.
Create a PHPUnit Run Configuration
Add a new run configuration of type PHPUnit. Choose the CLI interpreter you added earlier. For the configuration file, select either the project’s phpunit.xml or phpunit.xml.dist, or point directly to the Composer autoloader at vendor/autoload.php. Using the autoloader is sufficient for simple suites; a dedicated XML file is better when you need bootstrap files, environment variables, or test suite definitions.
Set the test scope to a single directory or file first. Running one test method validates the interpreter and autoload chain before you commit to a full suite.
A minimal phpunit.xml.dist might look like this:
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php" colors="true">
<testsuites>
<testsuite name="Unit">
<directory>tests/Unit</directory>
</testsuite>
</testsuites>
</phpunit>
In this example, the bootstrap attribute tells PHPUnit to load Composer’s autoloader before executing tests. Adjust the directory path to match your project layout.
Expected Checks
- Open Settings/Preferences > PHP and confirm the selected CLI interpreter displays the expected PHP version and the path to the loaded
php.ini. - Open a test class and click the green gutter icon next to a single test method. The result should appear in the Run tool window without interpreter or autoload errors.
- Navigate from a test class to a class inside a Composer package (for example, press
Ctrl+BorCmd+Bon a fully qualified class name). If indexing works, PhpStorm jumps to the vendor source file instead of reporting an unresolved reference. - Run Code > Inspect Code on the project or a test directory. Dependency classes should not trigger undefined-class inspections.
Recovery Options
If tests fail to start, re-check the interpreter path and the active php.ini in Settings. A missing extension or a version mismatch often surfaces as a startup error before any test logic runs.
If indexing stalls and code insight stops resolving vendor classes, invalidate caches and restart via File > Invalidate Caches / Restart. This forces a full re-index of vendor/.
If vendor/ is missing or incomplete, re-run composer install from the IDE terminal. To confirm the IDE detects the gap, temporarily rename vendor/ and observe whether the run configuration fails clearly rather than silently passing zero tests.
Only switch the run configuration to a remote interpreter—such as Docker, Vagrant, or SSH—after the local setup passes. Remote interpreters add path-mapping and extension-loading complexity that is difficult to diagnose when the baseline local configuration is also broken.
Limitations and Version Notes
PhpStorm menu labels and settings paths change between releases. The steps above assume a recent stable version, but you should verify the exact PHP and Composer pages in your installed IDE rather than relying on older screenshots.
A PHP CLI interpreter is not a web server SAPI. Extensions loaded by the web server may be absent in CLI mode, and vice versa. If your tests depend on an extension, confirm it is enabled in the CLI php.ini.
Align the interpreter with the project’s composer.json platform requirements. If the project requires PHP 8.2 but the local binary is 8.1, tests may fail to parse newer syntax or produce misleading runtime errors.
Do not commit IDE-specific run configurations or the .idea/ directory unless the team agrees. Prefer shared composer.json and phpunit.xml files so every developer and CI pipeline uses the same autoload and test bootstrap.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.