Composer dependency managerUltimate
warning
The following is only valid when the PHP plugin is installed and enabled.
IntelliJ IDEA integrates with the Composer dependency manager, which allows you to declare packages from Packagist or a custom repository as your project's dependencies and manage them from the IDE.
IntelliJ IDEA provides comprehensive coding assistance for working with composer.json as well as the dedicated user interface for running common Composer commands:
Managing Composer Projects with Composer,
Performing additional tasks.
When you run the above commands, IntelliJ IDEA displays their output via the Composer Log console.
If you wish to use the full range of Composer commands in a IntelliJ IDEA project, you can configure and run Composer as an external command-line tool.
Download and install Composer
For details on installing Composer, refer to the Composer official documentation.
If you work in a local environment, Composer commands in IntelliJ IDEA are run via the configured local PHP interpreter. You can download and install Composer manually as a system-wide standalone tool, or have IntelliJ IDEA download it automatically when you create a new Composer project, initialize Composer, or invoke other Composer commands in an existing project.
Additionally, IntelliJ IDEA enables you run Composer commands via any configured remote PHP interpreter.
Manage Composer projects
In IntelliJ IDEA, you can create new projects based on the Composer package of your choice or work with existing Composer projects. IntelliJ IDEA will resolve the dependencies and use the information from composer.json to automatically apply the certain configuration options.
Work with composer.json
The composer.json file describes the dependencies of your project and may also contain other metadata. IntelliJ IDEA provides comprehensive coding assistance for working with composer.json and lets you perform many Composer-related tasks directly from the code editor.
tip
Use the shortcut links on top of the composer.json editor panel to quickly install or update the project dependencies, open the Composer Log, and access additional commands.
If necessary, you can disable the shortcuts panel. In the Settings/Preferences dialog Ctrl+Alt+S, go to Languages & Frameworks | PHP | Composer and clear the Show composer.json top panel with quick actions checkbox.
Create a composer.json file
You can create composer.json files manually. If Composer hasn't yet been initialized in the project, a newly created composer.json will be automatically set as the project default.
- Do one of the following:
In the Project tool window Alt+1, select the directory or package in which you want to create a new file, and then choose File | New from the main menu.
Right-click the corresponding directory or package and select New from the context menu.
Press Alt+Insert.
In the popup menu, select composer.json File. IntelliJ IDEA creates a stub of the composer.json file and opens it in the editor.
tip
The composer.json file is created with default content. If necessary, you can customize the corresponding composer.json file template on the Editor | File and Code Templates page of the Settings/Preferences dialog Ctrl+Alt+S. Refer to File templates for details.
Use code completion in composer.json
Inside composer.json, press Ctrl+Space to use code completion when providing both the names of the sections and their content, for example:
License type and minimum-stability version,
Namespaces and paths in the
autoload
andautoload-dev
sections,Required PHP version and extensions as well as packages' names and versions in the
require
andrequire-dev
sections.
Gif
Use quick documentation in composer.json
Inside composer.json, press Ctrl+Q to view quick documentation for the element at caret.
Navigate from a composer.json record to the project entity or setting
Inside composer.json, position the caret at an entity such as an installed package, a class or a method within a script, a file path, or a url. Then do any of the following:
In the main menu, select Navigate | Declaration or Usages
Press Ctrl+B
Alternatively, Ctrl+Click the record.
GifIf you have a test framework or code quality tool installed as a project dependency, IntelliJ IDEA displays
next to the corresponding dependency record. Click it to jump directly to the corresponding Settings/Preferences page.
For details on using test frameworks, see Prepare for testing; for details on working with code quality tools, see and PHP code quality tools.
Manage dependencies
To install, update, or uninstall project dependencies, you need to update the records in the require
or require-dev
sections in composer.json and then run the corresponding Composer command.
To retrieve the available package updates and provide better coding assistance in composer.json, IntelliJ IDEA runs the update --dry-run command in background every time you open a project or modify composer.json. If necessary, you can disable running the command. In the Settings/Preferences dialog Ctrl+Alt+S, go to Languages & Frameworks | PHP | Composer and clear the Check for available package updates checkbox.
When you open a project or modify composer.json, IntelliJ IDEA checks whether the vendor directory is present. If it is missing, IntelliJ IDEA displays the notification message.

Click the Run 'composer install' shortcut link in the notification message to quickly install the project dependencies. If necessary, you can disable this notifcation by clearing the Notify about missing vendor directory checkbox on the PHP | Composer page of the Settings/Preferences dialog Ctrl+Alt+S.
Install dependencies
Inside composer.json, add the desired dependency record to the
require
orrequire-dev
section. Press Ctrl+Space to get code completion both for the package name and version.tip
When specifying the package version, you can provide version constrains, too, for example
>=1.0 <2.0
. See the Composer official documentation for details.Do one of the following:
Click the Install shortcut link on top of the editor panel.
If the Non-installed Composer packages inspection is enabled, IntelliJ IDEA will highlight the declared dependencies that are not currently installed. Press Alt+Enter and select whether you want to install a specific dependency or all dependencies at once.
When a new package is installed, IntelliJ IDEA creates a new subfolder under vendor and stores the package inside. If the composer.lock file. present in the current directory, the exact packages versions listed in it are installed. Otherwise, if the composer.lock file is missing, Composer will create it after installing the packages, thus locking your project to their specific versions.
tip
Learn more about adding dependencies on the Composer Official website.
Update dependencies
You can update packages to their latest versions individually, or update all the packages listed in the require
and require-dev
sections of composer.json at once.
When a new package version is available or the package versions requirements change, IntelliJ IDEA indicates this via the
icon in the editor gutter. It also provides the hint on the currently installed version and the version the package can be updated to.
Click
to update the package.
To update all packages, click the Update shortcut link on top of the composer.json editor panel.
tip
Learn more about updating dependencies on the Composer Official Website
Uninstall dependencies
Remove the package record from the
require
orrequire-dev
section of composer.json.Click the Update shortcut link on top of the composer.json editor panel.
Use a custom package repository
Besides Packagist, you can use a custom package repository.
Inside composer.json, create a repositories section for your repository:
{ "name": "vendor_name/package_name", "repositories": [ { "type": "composer", "url": "http://packages.example.com" } ] }
After IntelliJ IDEA retrieves the packages information, you can install, update, and uninstall packages as usual.
note
For details on setting up your own package repository, refer to the Composer official documentation.
Create and run Composer scripts
With Composer, you can create and run scripts, which are used for executing some custom code or package-specific commands during the Composer execution process.
Define a Composer script
Inside the
scripts
section of composer.json, create an event property, and list the desired scripts inside it. Each script can be a PHP callback defined as a static method, a command-line executable command, or a reference to an existing script.Use code completion Ctrl+Space to get suggestions for event names, classes' and static methods' names, and binaries installed under vendor/bin. To add a reference to an existing script, prepend it with the
@
symbol.Gif
Rename a Composer script
Position the caret at a script's definition or usage.
Invoke the Rename refactoring by selecting Refactor | Rename from the main menu or from the context menu, or press Shift+F6.
In the Rename dialog that opens, provide the desired name for a script.
Click Preview to observe possible changes in the Find tool window. Click Refactor to proceed.
Run a composer script
Click
in the gutter next to the script you want to execute. From the list, select Run <script name>.
Right-click inside the script you want to run and select Run <script name> from the context menu.
Position the caret at the script you want to execute, press Alt+Enter and select the Run <script name> intention action.
When the script is executed, IntelliJ IDEA automatically creates a dedicated temporary Composer Script run/debug configuration for it. You can save it as a permanent run/debug configuration if necessary.
Create a Composer script run/debug configuration
You can execute Composer scripts by using run configurations of the Composer Script type. With the run configuration, you can execute a script at any point, add it to the Services tool window, or a compound configuration. Refer to Working with Run/Debug Configurations for details.
Do any of the following:
In the editor, right-click inside the desired script record and select Create <configuration name> from the context menu.
Alternatively, choose Run | Edit Configurations from the main menu, then click
and choose Composer Script from the list.
Provide the run/debug configuration parameters:
Path to composer.json: in this field, provide the path to composer.json that contains the desired script's definition.
Script: from this list, select one of the defined Composer scripts to execute.
Command line parameters: in this field, type the additional command line parameters. These parameters will be passed as CLI arguments to the CLI handlers; inside PHP handlers, they can be retrieved as an array via
$event->getArguments()
calls.
Save a temporary Composer Script run/debug configuration
When you execute a Composer script from the editor, IntelliJ IDEA automatically creates a temporary run/debug configuration with the script parameters. A temporary run/debug configuration works the same way as a permanent run/debug configuration. You can change its settings using the Run/Debug Configuration dialog and optionally save it as permanent.
In the Run/Debug Configuration selector, choose Save <configuration name>.
In the Run/Debug Configuration dialog, select the configuration and click
.
Execute a Composer script using a run/debug configuration
In the Run/Debug Configuration selector, select the desired run configuration. Then click
on the main toolbar or press Shift+F10.
Press Alt+Shift+F10, select the desired run configuration from the list, and press Enter.
View the Composer log
When you execute a Composer-related command via the IntelliJ IDEA interface, the command's output is displayed in the dedicated Composer Log console:

tip
Click the composer.json link in the log to open the file in the editor.
Open Composer log
Having executed any Composer command for the first time, click the Show in log shortcut link in the Event log notification message:
Open composer.json in the editor and click the Show Log shortcut link on top of the editor panel.
View the folded Composer Log message
If a Composer command has been executed successfully, Composer Log will fold its execution details.
Click
in the gutter to unfold the message.
Hover the mouse over the ellipsis to view the message in a tooltip:
tip
To re-run a command, click
in the gutter.
When appointing a default composer.json in a project, you can enable IntelliJ IDEA's settings synchronization with composer.json. Composer Log will highlight such a change in the settings as it occurs. Click in the gutter it to quickly navigate to the corresponding , PHP, Test Frameworks, or PHP command line tools settings pages.
Run additional Composer commands
IntelliJ IDEA provides the user interface for a set of additional Composer commands.
From the composer.json context menu, select Composer | <command name>.
Open composer.json in the editor, click
on top of the composer.json editor panel, and choose the desired command from the list.
To run a command for the default composer.json, select Tools | Composer | <command name> from the main menu.
tip
Refer to the Composer documentation for the detailed description of all Composer commands.
If Composer execution is not set up, the Composer Settings dialog will open, prompting you to choose how the Composer commands will be executed:
To run commands via a globally installed composer executable, choose 'composer' executable and specify its location in the field.
To run commands via the local composer.phar archive, choose composer.phar. Then, either specify the location of the existing composer.phar file in the field or select the Download composer.phar from getcomposer.org checkbox to download a new instance of the file. The composer.phar file will be saved under the project root folder specified in the Location field.
Then, choose one of the configured local PHP interpreters from the PHP interpreter list. Refer to Configuring Local PHP Interpreters for details.
To run commands via a remote interpreter, choose Remote interpreter.
From the CLI Interpreter list, select a remote interpreter to use, or click
and configure a new one as described in Configuring Remote PHP Interpreters.
In most cases, IntelliJ IDEA detects path mappings automatically. If necessary, you can click
in the Path mappings field and specify them manually in the Edit Project Path Mappings that opens.
In the Composer executable field, provide the name of the Composer executable. You can click
, and locate the executable in the Select Path On The Server dialog that opens.
note
If you rely on Docker, you can use the composer Official Docker image, which is preconfigured as a remote interpreter in IntelliJ IDEA out of the box. This image is not intended for production use. If necessary, you can create and manage your own Docker images in IntelliJ IDEA as described in Managing images.
Run Composer from the command line
Command-line mode provides you with the full range of Composer commands. To use Composer in this mode, you need to configure it as an external command-line tool.
tip
Before you start, make sure the Command Line Tool Support plugin is installed on the Settings/Preferences | Plugins page, tab Marketplace, as described in Installing plugins from JetBrains repository.
You can have several instances of Composer configured and switch between them from one project to another by specifying the relevant one during Composer initialization.
Configure Composer as a command line tool
In the Settings/Preferences dialog Ctrl+Alt+S, go to Tools | Command Line Tool Support.
Click
on the toolbar.
In the Command Line Tools dialog, choose Composer from the list, and specify its visibility level (Project or Global ).
When you click OK, the dialog opens.
Specify how you want to launch Composer by choose one of the options: composer.phar or php script or composer executable. Depending on your choice, specify the paths to the PHP installation folder and composer.phar or to the composer executable file.
IntelliJ IDEA parses the contents of the specified .phar archive or executable file for Composer commands. When the file analysis is completed, IntelliJ IDEA returns to the Command Line Tools Support page where the specified file is added to the list of command line tools available in IntelliJ IDEA.
Click OK to apply changes and return to the Command Line Tool Support page. Optionally, click
to edit the tool properties, or
to customize the commands set. See Customize a tool for details.
Run a Composer command
From the main menu, choose Tools | Run Command or press Ctrl twice.
In the Run Anything window that opens, type the call of the command in the
<c> <command>
format.The command execution result is displayed in the Run tool window.
Gif
Terminate a command
Click
on the Run tool window toolbar.