Настройка phpstorm для php

Run applications

To be able to run an application from PhpStorm, you first need to configure a PHP interpreter as described in Configure local PHP interpreters and Configure remote PHP interpreters. After that, you can do any of the following:

Switch between configured PHP interpreters on the fly

  1. Press Ctrl+Shift+A and start typing Change PHP interpreter . In the suggestions list, select the Change PHP interpreter action. If necessary, you can assign a keyboard shortcut for this action either directly in the suggestions list by pressing Alt+Enter , or at a later point as described in Keyboard shortcuts.
  2. In the popup menu that opens, select one of the configured local or remote PHP interpreters.

The selected interpreter will be set as the default project interpreter on the PHP page of the Settings dialog ( Ctrl+Alt+S ). This will also affect configurations that use the default project interpreter (test frameworks’, quality tools’, and run/debug configurations) and commands run in the PhpStorm terminal.

Quick way

Run a single script

If you are not going to pass any parameters to your program, and your program does not require any specific actions to be performed before start, you can run it right from the editor.

Run PHP script from the editor

  • Right-click in the code editor, select Run from the context menu, and then select from the submenu.
  • To run a script, open it in the editor or select it in the Project tool window, and then select Run from the context menu.

The script will run, and a temporary run/debug configuration will be created for it.

Run the current file

On top of running applications from the editor, you can run single files using a dedicated option on the toolbar. The run and debug buttons are active and allow you to instantly run the currently opened file.

Running a single file from the toolbar

  1. In the editor, open the file that you want to run.
  2. Click next to the Current File option on the toolbar.

More options for running current file

You can access other runners from the submenu as well: expand the list and click the right arrow next to Current File . From the menu that opens, you can debug the code, run it with coverage, or open the run configuration to specify more options.

Customizable way

Use a run/debug configuration

If you are going to pass parameters to your program or otherwise customize the startup of your program, use a run/debug configuration.

  1. Create a run/debug configuration.
  2. On the main toolbar, select the run/debug configuration you are going to use. Ps run config menu
  3. Click or press Shift+F10 . Alternatively, press Alt+Shift+F10 , select the desired run configuration from the list, and press Enter . the Choose Run Configuration popupTo switch between running and debugging, press and hold Shift when selecting the configuration.

When the application starts, you can view its output and interact with it in the Run tool window. Every run/debug configuration creates a separate tab when you run it.

A tabs in the Run tool window

Use the Ctrl+F shortcut to search for text occurrences in the console output.

Читайте также:  Php class var types

To learn more about tool windows and how to manage them, see the Tool windows topic.

Open a file in a web browser

PhpStorm has a built-in web server that can be used to preview and debug your application. This server is always running and does not require any manual configuration. All the project files are served on the built-in server with the root URL http://localhost:/ , with respect to the project structure.

The built-in server can only serve static content like HTML, JavaScript and CSS. To use it with PHP files, you need a local PHP interpreter specified for your project. When the interpreter is configured, PhpStorm will automatically start the PHP Built-In Web Server and redirect all PHP requests to it as soon as you run your PHP application.

To open a file that is intended to be rendered by a web browser (HTML, XML, JSP, and so on), do one of the following:

Show in browser

  • Press Alt+F2 .
  • Right-click a file and select Open in Browser .
  • From the main menu, select View | Open in Browser .
  • Use the browser popup in the top right part of the editor window. Click the browser button to open the web server file URL, or Shift+Click it to open the local file URL.

The Open in Browser action is not available for other file types. However, you can still execute it using Find Action Ctrl+Shift+A .

Re-run applications

If you re-run an application, the output of the previous run is lost. To preserve the output of an application, click the Pin Tab button on the toolbar of the Run tool window. When a tab is pinned, new sessions are opened in another tab.

Stop and pause applications

When you stop a program, its process is interrupted and exits immediately. When you pause a program, it continues running in the background, but its output is suspended.

Stop a program

  • In the Run tool window, click on the toolbar. Alternatively, press Ctrl+F2 and select the process to stop.

Pause a program

  • Right-click in the Run tool window and select Pause Output from the context menu. Use the same toggle to resume the program.

Only the output is suspended. Pausing the output does not affect the execution of the program.

Show running processes

You can view the list of all active run or debug sessions and navigate between them.

A list of running applications

  • From the main menu, select Run | Show Running List . In the top-right corner of the editor, PhpStorm shows a list with all active applications.

Источник

PHP Script

Use this dialog to configure running and debugging of single PHP files locally using a PHP console.

Configuration area

In this area, specify the script to run or debug and the parameters to process it with, if applicable.

In this field, specify the location of the file to run or debug. Type the path to the file manually or click Browse and select the desired location in the Choose PHP File dialog that opens.

In this field, type the list of arguments to be passed to the PHP script, same way as if you were entering these parameters in the command line.

If necessary, click and type the desired switches in the Arguments dialog. Type each argument on a new line. As you type, they appear in the Arguments field with spaces as separators.

Читайте также:  Количество нулей питон тьютор

Command Line area

In this area, customize the behavior of the current PHP interpreter by specifying the options and arguments to be passed to the PHP executable file.

The list contains all the currently configured local and remote PHP interpreters. Choose one of the configured PHP interpreters from the list, or click and define a new interpreter as described in Configure local PHP interpreters and Configure remote PHP interpreters.

In this field, specify the options to be passed to the PHP executable file. They override the default behavior of the PHP interpreter or ensure that additional activities are performed.

If necessary, click and type the desired options in the Command Line Options dialog. Type each option on a new line. When you close the dialog, they are all displayed in the Command line options field with spaces as separators.

In this field, specify the location of the files that are outside the folder with the script and are referenced in your script through relative paths. Type the path manually or click the Browse button and select the desired folder in the dialog that opens.

This setting does not block the script execution because the script location is always specified through a full path.

In this field, specify the environment variables be passed to the built-in server. See Environment Variables in Apache for details.

Docker Compose area

This area only appears if you select a Docker Compose-based remote interpreter in the Interpreter field. Here, you can add some Docker Compose commands with options to the run configuration.

You can use the following commands of the Docker Compose Command-Line Interface:

up: Builds, creates, starts, and attaches to containers for a service.

  • —abort-on-container-exit
  • —build
  • —exit-code-from SERVICE
  • —scale SERVICE=NUM.
  • —timeout TIMEOUT

run: Runs a one-time command against a service.

  • —entrypoint CMD
  • -l, —label KEY=VAL
  • —name NAME
  • -p, —publish=[]
  • —rm
  • —service-ports
  • —use-aliases
  • -u, —user=»»
  • -v, —volume=[]

exec: Runs arbitrary commands in your services.

Use this field to preview the complete command string.

For example, the up —build exec —user jetbrains combination in the Commands and options field produces the following output in the preview:

Debug area

Use the controls in this area to configure behaviour of the debugging tool.

Select this checkbox to have the debugging tool stop at the first line of the source code.

Common settings

When you edit a run configuration (but not a run configuration template), you can specify the following options:

Specify a name for the run configuration to quickly identify it among others when editing or running.

Allow running multiple instances of this run configuration in parallel.

By default, it is disabled, and when you start this configuration while another instance is still running, PhpStorm suggests stopping the running instance and starting another one. This is helpful when a run configuration consumes a lot of resources and there is no good reason to run multiple instances.

Save the file with the run configuration settings to share it with other team members. The default location is .idea/runConfigurations . However, if you do not want to share the .idea directory, you can save the configuration to any other directory within the project.

Читайте также:  Python time and date format

By default, it is disabled, and PhpStorm stores run configuration settings in .idea/workspace.xml .

Toolbar

The tree view of run/debug configurations has a toolbar that helps you manage configurations available in your project as well as adjust default configurations templates.

Create a run/debug configuration.

Источник

Configure local PHP interpreters

A local PHP interpreter is a PHP engine installed on your computer opposite to a remote PHP interpreter that can be installed on a remote host or in a virtual environment set up in a Vagrant instance , see Configure remote PHP interpreters.

Before you begin, install a PHP engine either as part of an AMP package or separately.

  1. Press Ctrl+Alt+S to open the IDE settings and select PHP .
  2. On the PHP page that opens, click next to the CLI Interpreter list.
  3. In the CLI Interpreters dialog that opens, click in the left-hand pane, then choose Local from the popup menu. If you already have a local interpreter configured in PhpStorm, it is also shown from the menu and the menu item changes to Other Local .
  4. In the right-hand pane of the dialog, specify the PHP interpreter’s settings.
    1. In the Name field, type the identifier to distinguish the interpreter from others, for example, php_installation_ .
    2. Specify the PHP engine installation directory in the PHP executable field. Type the path manually or click and select the relevant folder in the dialog that opens. PhpStorm displays the version of the PHP engine detected in the specified folder and the debugger associated with this PHP engine in the php.ini file.

    -dxdebug.mode=debug -dxdebug.client_host=127.0.0.1 -dxdebug.client_port=9003 -dxdebug.start_upon_error=default For example, if you specify the -dxdebug.start_upon_error=yes directive it will override the default -dxdebug.start_upon_error=default directive and thus switch Xdebug to the Just-In-Time (JIT) mode, see Debug in the Just-In-Time mode for details.

    -dxdebug.remote_enable=1 -dxdebug.remote_host=127.0.0.1 -dxdebug.remote_port=9000 -dxdebug.remote_mode=req For example, if you specify the -dxdebug.remote_mode=jit directive it will override the default -dxdebug.remote_mode=req directive and thus switch Xdebug to the Just-In-Time (JIT) mode, see Debug in the Just-In-Time mode for details.

    • To add a new entry, click . In the new line, that is added to the list, specify the name of the new entry and its value in the Name and Value fields respectively. You can add as many entries as you need, just keep in mind that they will be transformed into a command line with its length limited to 256 characters.
    • To delete an entry, select it in the list and click .
    • To change the order of entries, click or .

    Upon clicking OK , you return to the CLI Interpreters dialog, where the entries are transformed into a command line.

    Switch between configured PHP interpreters on the fly

    1. Press Ctrl+Shift+A and start typing Change PHP interpreter . In the suggestions list, select the Change PHP interpreter action. If necessary, you can assign a keyboard shortcut for this action either directly in the suggestions list by pressing Alt+Enter , or at a later point as described in Keyboard shortcuts.
    2. In the popup menu that opens, select one of the configured local or remote PHP interpreters.

    The selected interpreter will be set as the default project interpreter on the PHP page of the Settings dialog ( Ctrl+Alt+S ). This will also affect configurations that use the default project interpreter (test frameworks’, quality tools’, and run/debug configurations) and commands run in the PhpStorm terminal.

    Источник

Оцените статью