Composer Dependency Manager
PhpStorm integrates with the Composer Dependency Manager so you can install PHP-related frameworks right from the IDE.
PhpStorm provides a dedicated interface for initializing a project and adding dependencies. Note that in this mode, you can use Composer only in the current project.
To run any Composer command in any PhpStorm project, use the tool in the command-line mode, see How do I run Composer from the command line in PhpStorm? below.
Check Composer Support in PhpStorm for step-by-step guidance and examples.
Where do I get Composer from?
Option 1: Download Composer
Download composer.phar
from the Composer Official website.
Option 2: Update Composer to the latest version
On the main menu, choose Tools | Composer | Self-Update. Learn more from the Composer Official website.
How do I initialize Composer in a PhpStorm project?
- Run Init Composer
On the main menu, choose Tools | Composer | Init Composer. The Composer Settings Dialog opens. - Specify the PHP interpreter to use
Choose one of the configured local PHP interpreters from the list in the Execution area. See Configuring Local PHP Interpreters for details. - Specify the composer.phar to use
In the Execution area, specify the path tocomposer.phar
. If you have not downloaded it yet, click the Download link and specify the folder to storecomposer.phar
in. - Complete the generated composer.json
When you click OK, the Composer Settings dialog is closed, PhpStorm creates a stub of thecomposer.json
file and opens it in the editor. Complete the code or accept the default values. For more details, see Composer.json: Project Setup.
How do I set up an external Composer project in PhpStorm?
- Open your project
Click Open on the Welcome screen or choose File | Open on the main menu, then choose the folder where your Composer project is stored. PhpStorm shows a notification: - Initialize Composer
Click Initialize. PhpStorm shows the Composer dialog where you need to specify the location ofcomposer.json
. If PhpStorm detects a configuration file, the Path to composer.json field is already filled in: - Complete configuration for executing Composer commands
Open the Composer page (File | Settings | Languages and Frameworks | PHP | Composer for Windows and Linux or PhpStorm | Preferences | Languages and Frameworks | PHP | Composer for macOS).Alternatively, if you have one
composer.json
in your project, choose Tools | Composer | Install on the main menu. PhpStorm shows the following dialog: In either case, specify the PHP interpreter and thecomposer.phar
to use. See How do I initialize Composer in a PhpStorm project? above. - Install the dependencies
- If you have only one
composer.json
in your project, choose Tools | Composer | Install on the main menu. See also How do I appoint the default composer.json in a PhpStorm project?. - If you have several
composer.json
files, choose Composer | Install from the context menu of the relevant one.
- If you have only one
How do I appoint a default composer.json in a PhpStorm project?
You can have several composer.json
files in one PhpStorm project. For each composer.json
, actions are invoked from its context menu in the editor or in the Project view. You can also appoint the default composer.json for your PhpStorm project. Composer actions for it are invoked from Tools | Composer on the main menu.
- Open the Composer page
Choose File | Settings | Languages and Frameworks | PHP | Composer for Windows and Linux or PhpStorm | Preferences | Languages and Frameworks | PHP | Composer for macOS. - Specify the location of the default composer.json
If you have only one Composer configuration file in your PhpStorm project, the Path to composer.json field is filled in automatically. - Configure the open-for-edit status of Composer packages
To protect packages undervendor/*/*
against editing, leave the Add packages as libraries check box selected (this is the default setting).
If you want to edit Composer packages undervendor/*/*
, clear the Add packages as libraries check box. - Enable settings synchronization
Make sure the Synchronize IDE settings with composer.json check box is selected to automatically detect the PHP language level and configure project Source and Test roots based on the configuration fromcomposer.json
.
PhpStorm is aware of PSR-0/PSR-4 source roots and of their namespace prefixes declared in theautoload
andautoload-dev
sections incomposer.json
. PhpStorm also detects the PHP language level based on thephp
setting in therequire
section.
Becausecomposer.json
contains the most up-to-date information about the project configuration, this automatic synchronization ensures that the Source and Test folder exactly match the project structure and the correct PHP language level is set automatically. Learn more about PSR and autoload from the Composer official website. For examples and details in synchronizing settings, see PhpStorm blog.
How do I install dependencies?
You can install specific packages one-by-one, PhpStorm will update your composer.json
automatically. Alternatively, you can list the packages you need in the require
and require-dev
sections and then install them all at once.
Learn more about adding dependencies from the Composer Official website.
Option 1: Install packages one-by-one
- Open the Manage Composer Dependencies dialog
On the context menu ofcomposer.json
, choose Composer | Manage Dependencies. - Choose the package to add
Select the required package from the Available Packages list, possibly using the search field. The list shows all the available packages, the packages that are already installed are marked with a tick.Choose the relevant version from the Version to install list.
- Optionally, customize the package installation
Expand the Settings hidden area and specify the advanced installation options. In the Command line parameters text box, type the additional command line parameters. For example, to have a dependency added to therequire-dev
section instead of the defaultrequire
section, type--dev
. For more information about Composer command line options during installation, see https://getcomposer.org/doc/03-cli.md.
Click Install to start installation. To leave the dialog, click Close.
When the installation is completed, PhpStorm creates a new subfolder under vendor, stores the new package in this subfolder, and adds the new package to the require
or require-dev
section of composer.json
.
Option 2: Install all dependencies at once
On the context menu of composer.json
, choose Composer | Install. PhpStorm installs all the packages listed in the require
and require-dev
sections.
How do I update dependencies?
You can update specific packages to the latest version one-by-one, PhpStorm will update your composer.json
automatically. Alternatively, you can update all the packages listed in the require
and require-dev
sections at once.
Option 1: Update packages one-by-one
- Open the Manage Composer Dependencies dialog
On the context menu ofcomposer.json
, choose Composer | Manage Dependencies. - Choose the package to update
Select the required package from the Available Packages list among the packages marked with a tick and click Update.
Option 2: Update all dependencies at once
On the context menu of composer.json
, choose Composer | Update. PhpStorm updates all the packages listed in the require
and require-dev
sections.
How do I uninstall a dependency?
- Open the Manage Composer Dependencies dialog
On the context menu ofcomposer.json
, choose Composer | Manage Dependencies. - Choose the package to uninstall
In the Available Packages list, select the package to uninstall among the packages marked with a tick and click Remove.
When the uninstallation is completed, PhpStorm updates therequire
orrequire-dev
section ofcomposer.json
automatically.
How do I generate a Composer project stub?
- Open the New Project dialog
Choose File | New Project or click Create New Project on the Welcome screen. - Choose the project type and location
In the left-hand pane, click Composer Project. In the Location field on the right-hand pane, specify the folder where the project will be created. - Choose composer.phar to use
- To use commands from a previously downloaded
composer.phar
, choose Use existing composer.phar and specify its location in the text box. - To download a new instance of Composer, choose Download composer.phar from getcomposer.org. The
composer.phar
file will be saved under the project root folder specified in the Location text box.
- To use commands from a previously downloaded
- Specify PHP interpreter to use
Choose one of the configured local PHP interpreters from the list, see Configuring Local PHP Interpreters for details. - Specify the package to install during the project creation
Select the package to add from the Available Packages list, possibly using the search field, and choose the relevant version from the Version to install list. - Optionally
In the Command line parameters text box, type the additional command line parameters. For example, to have a package added to therequire-dev
section instead of the defaultrequire
section, type--dev
. For more information about Composer command line options during installation, see https://getcomposer.org/doc/03-cli.md.
When you click Create, the create-project
command is invoked with the selected package. This results in creating a Composer project whose configuration and structure depends on the selected package, see https://getcomposer.org/doc/03-cli.md for details. After that a PhpStorm project opens.
How do I run Composer from the command line in PhpStorm?
In the command-line mode the full range of Composer command is at your disposal. To use Composer in this mode, you need to configure it as an external command-line tool. For more details, see PHP Command Line Tools.
Step 1: Integrate Composer with PhpStorm as an external command-line tool
- Open the Composer dialog
Choose File | Settings | Tools | Command Line Tool Support for Windows and Linux or PhpStorm | Preferences | Tools | Command Line Tool Support for macOS. On the Command Line Tool Support page that opens, click and choose Composer from the list. - Specify how you want to launch Composer
Choose one of the options composer.phar or php script or composer executable. Depending on your choice, specify the paths to PHP installation folder andcomposer.phar
or tocomposer
executable file.PhpStorm parses the contents of the specified
.phar
archive or executable file for Composer commands. When the file analyses is completed, PhpStorm returns to the Command Line Tools Support page where the specified file is added to the list of command line tools available in PhpStorm. - Complete Composer configuration
On the Command Line Tools Support page where Composer is added to the list of tools, select the Enable check box, specify the alias to use in calls, customize the command set if necessary, and choose where to show the Input pane for running commands. See How do I customize a tool? and Input pane location for details.
Step 2: Initialize a Composer project
Open the Input pane (Tools | Run Command), type с init
at the command prompt, and answer the questions of the wizard. Learn more from the Composer Official website.
Step 3: Run Composer commands
Open the Input pane (Tools | Run Command) and type <alias>
(c
by default) and press Ctrl+Space to invoke completion. The result of command execution is shown in the Output tab with the name of the command. Learn more from How do I run a command?.