PhpStorm 2019.2 Help

External tools

You can define standalone third-party applications as external tools and run them from PhpStorm. For example, you might want to run a code generator or analyzer, preprocessor or postprocessor, a database utility, and so on.

You can pass contextual information from your project to the external tool as command-line arguments (for example, the currently selected or open file, the project source path, and so on), view the output produced by the tool, configure to launch the tool before a run/debug configuration, and more.

There are different types of external tools that you can use with PhpStorm:

  • Local external tools are applications that run locally on your machine.

  • Remote SSH external tools are executed on a remote server over SSH.

Add a local external tool

This example demonstrates how you can add OptiPNG as an external tool and use it to quickly optimize images in your project from PhpStorm.

  1. In the Settings/Preferences dialog (Ctrl+Alt+S), select Tools | External Tools.

  2. Click the Add button and specify the following settings:

    The Create Tool dialog
    • Name: The name of the tool that will be displayed in the PhpStorm interface (the Tools menu and context menus).

    • Group: The name of the group to which the tool belongs. You can select an existing group or type the name of a new group.

    • Description: A meaningful description of the tool.

    • Program: The name of the executable file. Specify it with an absolute path if the containing directory is not in your PATH environment variable.

    • Arguments: The arguments passed to the executable file, as you would specify them on the command line.

    • Working directory: The path to the current working directory from which the tool is executed.

    In our case, OptiPNG will be run with the -o4 $FilePath$ arguments. You can use macros that can refer to the project name, the current file path, a path to the PHP executable, and so on. Clicking the Insert macro button will open the Macros Dialog listing all available macros and their values.

  3. Click OK to add the tool and then apply the changes.

To run the added tool on the selected image, do one of the following:

  • From the main menu, select Tools | Images | Optimize PNG.

  • Right-click a file in the Project tool window and select Tools | Images | Optimize PNG from the context menu.

    Run External tool
  • In the Settings/Preferences dialog (Ctrl+Alt+S), select Keymap, find the Optimize PNG action under the External Tools node, and assign a shortcut for it. Use the shortcut to run the tool.

    Create a shortcut for an external tool

When the tool runs, its output is displayed in the Run tool window:

Running External Tool

Add a remote SSH external tool

Remote SSH external tools are configured similarly to local external tools, but also define the remote server on which they are executed and require credentials for connecting to it via SSH. For details on working with the built-in SSh terminal, see Running SSH Terminal.

This example demonstrates how you can add date as a remote SSH external tool that is executed on a remote server and returns the current date and time on it.

  1. In the Settings/Preferences dialog (Ctrl+Alt+S), select Tools | Remote SSH External Tools.

  2. Click the Add button and specify the following settings:

    The Create Tool dialog

    This dialog provides the same set of settings as when you add a local external tool, but selecting the remote server is also suggested. This can be one of your configured deployment servers, the default remote interpreter, or a Vagrant box. By default, PhpStorm will ask you for the host, port, and relevant SSH credentials every time you run the tool on the deployment server.

  3. Click OK to add the tool and then apply the changes.

To run the added date tool on a remote server, do one of the following:

  • From the main menu, select Tools | Remote tools | Date and time.

  • In the Settings/Preferences dialog (Ctrl+Alt+S), select Keymap, find the Date and time action, and assign a shortcut for it. Use the shortcut to run the tool.

After you specify the host, port, and credentials, PhpStorm will connect to the server via SSH and run the date command, returning the output to the Run tool window in PhpStorm.

Last modified: 19 September 2019

See Also

Reference:

Tutorials and Examples: