I’m trying to connect my PhpStorm debugger with PHPUnit. I’m using Docker env and inside docker PHPUnit is working properly. Problem is when I click on 'tests' directory PPM. PhpStorm provides Docker support using the Docker plugin. The plugin is bundled and enabled by default. The Docker plugin is bundled with PhpStorm and activated by default. If the plugin is disabled, enable it on the Settings/Preferences Plugins page as described in Managing plugins. I’m trying to connect my PhpStorm debugger with PHPUnit. I’m using Docker env and inside docker PHPUnit is working properly. Problem is when I click on 'tests' directory PPM.
- Phpstorm Phpunit Dockers
- Phpstorm Docker Xdebug Not Working
- Php Docker Xdebug Phpstorm
- Phpstorm Run Phpunit In Docker
- Phpstorm Xdebug Docker
- Phpstorm Docker Phpunit Version Not Installed
- Phpunit Setup
Docker enables developers to deploy applications inside containers for testing code in an environment identical to production. PhpStorm provides Docker support using the Docker plugin. The plugin is bundled and enabled by default. The Docker plugin is bundled with PhpStorm and activated by default. If the plugin is disabled, enable it on the Settings/Preferences | Plugins page as described in Managing plugins.
Enable Docker support
Install and run Docker.
For more information, see the Docker documentation.
Configure the Docker daemon connection settings:
In the Settings/Preferences dialog Ctrl+Alt+S, select Build, Execution, Deployment | Docker.
Click to add a Docker configuration and specify how to connect to the Docker daemon.
The connection settings depend on your Docker version and operating system. For more information, see Docker configuration.
The Connection successful message should appear at the bottom of the dialog.
The default docker-machine value is fine if:
The actual name of the executable file is docker-machine.
The path to the directory where the file is located is included in the
Path
environment variable.
To specify an actual path to the executable file, click and select the file in the dialog that opens.
If no message appears, check the Docker Machine executable setting on the Docker | Tools page.
The Path mappings table is used to map local folders to corresponding directories in the Docker virtual machine's file system. Only specified folders will be available for volume binding.
This table is not available on Linux, because when running Docker on Linux, any folder is available for volume binding.
Connect to the Docker daemon.
The configured Docker connection should appear in the Services tool window (View | Tool Windows | Services or Alt+8 ). Select the Docker node , and click , or select Connect from the context menu.
To edit the Docker connection settings, select the Docker node and click on the toolbar, or select Edit Configuration from the context menu.
The Services tool window (View | Tool Windows | Services or Alt+8) enables you to pull and push images, create and run containers, manage Docker Compose, and so on. As with other tool windows, you can start typing the name of an image or container to highlight the matching items.
Managing images
Docker images are executable packages for running containers. Depending on your development needs, you can use Docker for the following:
- Pull pre-built images from a Docker registry
For example, you can pull an image that runs a Postgres server container to test how your application will interact with your production database.
- Build images locally from a Dockerfile
For example, you can build an image that runs a container with some specific version of PHP to execute your application inside it.
- Push your images to a Docker registry
For example, if you want to demonstrate to someone how your application runs in some specific version of language instead of setting up the proper environment, they can run a container from your image.
Images are distributed via the Docker registry. Docker Hub is the default public registry with all of the most common images: various Linux flavors, database management systems, web servers, runtimes, and so on. There are other public and private Docker registries, and you can also deploy your own registry server.
PhpStorm Docker registry provides a selection of preconfigured Docker images serving common PHP development needs.
You do not need to configure a registry if you are going to use only Docker Hub.
In the Settings/Preferences dialog Ctrl+Alt+S, select Build, Execution, Deployment | Docker | Registry.
Click to add a Docker registry configuration and specify how to connect to the registry. If you specify the credentials, PhpStorm will automatically check the connection to the registry. The Connection successful message should appear at the bottom of the dialog.
In the Services tool window, select the Images node.
Select the Docker registry and specify the repository and tag (name and version of the image, for example,
php-71-apache-xdebug-26:latest
).Press Ctrl+Enter to run docker pull.
When you are editing a Dockerfile, PhpStorm provides completion for images from the configured registries. You can also hold down Ctrl and click an image name to open its page in a web browser.
Open the Dockerfile from which you want to build the image.
Click in the gutter and select to build the image.
PhpStorm runs the docker build command.
In the Services tool window, select the image that you want to upload and click or select Push Image from the context menu.
Select the Docker registry and specify the repository and tag (name and version of the image, for example,
my-app:v2
).Click OK to run the docker push command.
Images that you pull or build are stored locally and are listed in the Services tool window under Images. When you select an image, you can view its ID or copy it to the clipboard by clicking the button on the Properties tab.
To display detailed information about an image, right-click it and select Inspect from the context menu. PhpStorm runs the docker image inspect command and prints the output to the Inspection tab.
Images with no tags <none>:<none>
can be one of the following:
Intermediate images that serve as layers for other images and do not take up any space
Dangling images that remain when you rebuild an image based on a newer version of another image. You should regularly prune dangling images to preserve disk space.
Phpstorm Phpunit Dockers
To hide untagged images from the list, click on the Docker toolbar, and then click Untagged Images to remove the check mark.
To delete one or several images, select them in the list and click .
Running containers
Containers are runtime instances of corresponding images. For more information, see the docker run command reference.
PhpStorm uses run configurations (Run | Edit Configurations) to run Docker containers. There are three types of Docker run configurations:
Docker Image: Created automatically when you run a container from an existing image. You can run it from a locally existing Docker image that you either pulled or built previously.
Dockerfile: Created automatically when you run a container from a Dockerfile. This configuration builds an image from the Dockerfile, and then derives a container from this image.
Docker-compose: Created automatically when you run a multi-container Docker application from a Docker Compose file.
Any Docker run configuration can also be created manually. From the main menu, select Run | Edit Configurations. Then click , point to Docker, and select the desired type of run configuration.
In the Services tool window, select an image and click or select Create Container from the context menu.
In the Create container popup, click Create.
If you already have a Docker run configuration for this image, the Create container popup will also contain the name of that run configuration as an option.
In the Create Docker Configuration dialog that opens, you can provide a unique name for the configuration and specify a name for the container. If you leave the Container name field empty, Docker will give it a random unique name.
When you are done, click Run to launch the new configuration.
Open the Dockerfile from which you want to run the container.
Click in the gutter and select to run the container on a specific Docker node.
This creates and starts a run configuration with default settings, which builds an image based on the Dockerfile and then runs a container based on this image.
To create a run configuration with custom settings, click in the gutter and select New Run Configuration. You can specify a custom tag for the built image, as well as a name for the container, and a context folder from which to read the Dockerfile. The context folder can be useful, for example, if you have some artifacts outside of the scope of your Dockerfile, which you would like to add to the file system of the image.
You can right-click the Dockerfile in the Project tool window for the following useful actions:
Run the container from the Dockerfile
Save the run configuration for the Dockerfile
Select the run configuration for this Dockerfile to make it active
Command-line options
When running a container on the command line, the following syntax is used:
All optional parameters can be specified in the corresponding Docker run configuration fields.
To open a run configuration, right-click a container and select Edit Configuration, or use the gutter icon menu in the Dockerfile, or select Run | Edit Configurations from the main menu.
Options are specified in the Command line options field. In the previous screenshot, the container is connected to the my-net
network and is assigned an alias my-app
.
Commands and arguments to be executed when starting the container are specified in the Entrypoint and Command fields. These fields override the corresponding ENTRYPOINT and CMD instructions in the Dockerfile.
Not all docker run
options are supported. If you would like to request support for some option, leave a comment in IDEA-181088.
The Command preview field shows the actual Docker command used for this run configuration.
You can also configure the following container settings in the run configuration:
Bind mounts
Docker can mount a file or directory from the host machine to the container using the -v
or --volume
option. You can configure this in the Docker run configuration using the Bind mounts field.
If you are using Docker for Windows, you need to enable drive sharing. Open Docker settings, select Shared Drives, select the drive (for example, C:) that you want to make available to your containers, and restart Docker.
Make sure that the corresponding path mappings are configured in the Docker connection settings (the Path mappings table).
Click in the Bind mounts field and add bindings by specifying the host directory and the corresponding path in the container where it should be mounted. Select Read only if you want to disable writing to the container volume. For example, if you want to mount some local MySQL data directory (/Users/Shared/mysql) to the MySQL data directory inside the container (/var/lib/mysql ), this can be configured as illustrated on the previous screenshot.
If you expand the Command preview field, you will see that the following line was added:
This can be used in the Command line options field instead of creating the list of volume bindings using the Bind Mounts dialog.
View and modify volume bindings for a running container
In the Services tool window, select the container and then select the Volume Bindings tab.
To create a new binding, click . To edit an existing one, select the binding and click .
Specify the settings as necessary and click Save to apply the changes.
The container is stopped and removed, and a new container is created with the specified changes. However, changes are not saved in the corresponding run configuration.
Bind ports
Docker can map specific ports on the host machine to ports in the container using the -p
or --publish
option. This can be used to make the container externally accessible. In the Docker run configuration, you can choose to expose all container ports to the host or use the Bind ports field to specify port mapping.
Click in the Bind ports field and bindings by specifying which ports on the host should be mapped to which ports in the container. You can also provide a specific host IP from which the port should be accessible (for example, you can set it to 127.0.0.1 to make it accessible only locally, or set it to 0.0.0.0 to open it for all computers in your network).
If you already have MySQL running on the Docker host port %5432%, you can map port %5433% on the host to %5432% inside the container as illustrated on the previous screenshot. This will make MySQL running inside the container accessible via port %5433% on the host.
If you expand the Command preview field, you will see that the following line was added:
This can be used in the Command line options field instead of creating the list of port bindings using the Port Bindings dialog.
View and modify port bindings for a running container
In the Services tool window, select the container and then select the Port Bindings tab.
To create a new binding, click . To edit an existing one, select the binding and click . If the Publish all ports checkbox is selected, clear it to be able to specify individual port mappings.
Specify the settings as necessary and click Save to apply changes.
The container is stopped and removed, and a new container is created with the specified changes. However, changes are not saved in the corresponding run configuration.
Environment variables
Environment variables are usually set in the Dockerfile associated with the base image that you are using. There are also environment variables that Docker sets automatically for each new container. You can specify additional variables and redefine the ones that Docker sets using the -e
or --env
option. In a Docker run configuration, you can use the Environment variables field to configure environment variables.
Click in the Environment variables field to add names and values for variables. For example, if you want to connect to MySQL with a specific username by default (instead of the operating system name of the user running the application), you can define the MYSQL_USER
variable as illustrated on the previous screenshot.
If you expand the Command preview field, you will see that the following line was added:
This can be used in the Command line options field instead of creating the list of names and values using the Environment Variables dialog. If you need to pass sensitive information (passwords, secrets, and so on) as environment variables, you can use the --env-file
option to specify a file with this information.
View and modify environment variables for a running container
In the Services tool window, select the container and then select the Environment variables tab.
To add a new variable, click . To edit an existing one, select the variable and click .
Specify the settings as necessary and click Save to apply changes.
The container is stopped and removed, and a new container is created with the specified changes. However, changes are not saved in the corresponding run configuration.
Build-time arguments
Docker can define build-time values for certain environment variables that do not persist in the intermediate or final images using the --build-arg
option for docker build
. These must be specified in the ARG
instruction of the Dockerfile with a default value. You can configure build-time arguments in the Docker run configuration using the Build args field.
For example, you can use build-time arguments to build the image with a specific version of MySQL. To do this, add the ARG
instruction to the beginning of your Dockerfile:
The MSTAG
variable in this case will default to latest
if you do not redefine it as a build-time argument. So by default, this Dockerfile will produce an image with the latest available MySQL version. However, you can use the Build Args field to redefine the MSTAG
variable.
In the previous screenshot, MSTAG
is set to 5.5
, which will instruct Docker to pull mysql:5.5
. When you deploy this run configuration, it will build an image and run the container with MySQL version 5.5.
To check this, execute mysql -V
inside the container and see the output: it should be mysql Ver 14.14 Distrib 5.5.60
or some later version.
If you expand the Command preview field, you will see that the following option was added to the docker build
command:
Interacting with containers
Created containers are listed in the Services tool window. When you select a container, you can view its ID (and the ID of the corresponding image) and copy it to the clipboard using on the Properties tab. You can also specify a new name for the container and click Save to start another container with this new name from the same image.
By default, the Services tool window displays all containers, including those that are not running. To hide stopped containers from the list, click , and then click Show Stopped Containers to remove the checkbox.
If a container was created using a Docker run configuration, to view its deployment log, select it and open the Deploy log tab. To view the log messages from the container's STDOUT
and STDERR
, select it and open the Log tab. For more information, see the docker logs command reference.
You can browse the files inside a running container using the Files tab. Select any file and click to open it remotely in the editor or click to create a copy of the file as a scratch.
The file browser may not work by default for containers that don't have the full ls
package, for example, images that are based on Alpine, Photon, and BusyBox. To use it, you can add the following command in the Dockerfile:
In the Services tool window, right-click the container name and then click Exec.
In the Run command in container popup, click Create.
In the Exec dialog, type the command and click OK. For example:
ls /tmp
List the contents of the /tmp directory
mkdir /tmp/my-new-dir
Create the my-new-dir directory inside the /tmp directory
/bin/bash
Start a bash
session
For more information, see the docker exec command reference.
View detailed information about a running container
In the Services tool window, right-click the container name and then click Inspect.
The output is rendered as a JSON array on the Inspection tab.
For more information, see the docker inspect command reference.
In the Services tool window, right-click the container name and then click Show processes.
The output is rendered as a JSON array on the Processes tab.
For more information, see the docker top command reference.
Attach a console to the output of an executable container
In the Services tool window, right-click the container and then click Attach.
The console is attached to the output of the ENTRYPOINT process running inside a container, and is rendered on the Attached console tab.
For more information, see the docker attach command reference.
Docker Compose
Docker Compose is used to run multi-container applications. For example, you can run a web server, backend database, and your application code as separate services. Each service can be scaled by adding more containers if necessary. This enables you to perform efficient development and testing in a dynamic environment, similar to production.
Run a multi-container Docker application
Define necessary services in one or several Docker Compose files.
From the main menu, select Run | Edit Configurations.
Click , point to Docker and then click Docker-compose.
Specify the Docker Compose files that define services which you want to run in containers. If necessary, you can restrict the services that this configuration will start, specify environment variables, and force building of images before starting corresponding containers (that is, add the
--build
option for the docker-compose up command).When the run configuration is ready, execute it.
To quickly create a Docker-compose run configuration and run it with default settings, right-click a Docker Compose file in the Project tool window and click Run in the context menu. You can also use gutter icons and the context menu in the Docker Compose file to control services.
When Docker Compose runs your multi-container application, you can use the Services tool window to control specific services and interact with containers. The containers are listed under the dedicated Compose nodes, not under the Containers node (which is only for standalone containers).
In the Services tool window, select the service you want to scale and click or select Scale from the context menu.
Specify how many containers you want for this service and click OK.
In the Services tool window, select the service and click or select Stop from the context menu.
In the Services tool window, select the Compose node and click .
In the Services tool window, select the Compose node and click .
This stops and removes containers along with all related networks, volumes, and images.
Open the Docker Compose file that was used to run the application
In the Services tool window, right-click the Compose node or a nested service node and then click Jump to Source in the context menu F4.
The Docker-compose run configuration will identify environment files with the .env suffix if they are located in the same directory as the Docker Compose file.
Troubleshooting
If you encounter one of the following problems, try the corresponding suggested solution.
Make sure that:
Docker is running.
Your Docker connection settings are correct.
If you are using Docker for Windows, enable the Expose daemon on tcp://localhost:2375 without TLS option in the General section of your Docker settings.
If you are using Docker Toolbox, make sure that Docker Machine is running and its executable is specified correctly in the Settings/Preferences dialog Ctrl+Alt+S under Build, Execution, Deployment | Docker | Tools.
Phpstorm Docker Xdebug Not Working
When you try to pull an image, the following message is displayed:
Php Docker Xdebug Phpstorm
In this case, go to <your_home_dir>/.docker directory and delete the config.json file.
Make sure that the Docker Compose executable is specified correctly in the Settings/Preferences dialog Ctrl+Alt+S under Build, Execution, Deployment | Docker | Tools.
Make sure that the corresponding container ports are exposed. Use the EXPOSE command in your Dockerfile.
Unable to associate existing Dockerfiles or Docker Compose files with relevant types
When you create new Dockerfiles or Docker compose files, PhpStorm automatically identifies their type. If a file type is not evident from its name, you will be prompted to select the file type manually. To associate an existing file with the correct type, right-click it in the Project view and select Associate with File Type from the context menu.
If the Associate with File Type actions is disabled, this probably means that the filename is registered as a pattern for current file type. For example, if you have a Dockerfile with a custom name that is recognized as a text file, you cannot associate it with the Dockerfile type. To remove the file type pattern, do the following:
In the Settings/Preferences dialog Ctrl+Alt+S, select Editor | File types.
Select the relevant file type (in this case: Text) and remove the pattern with the name of the file.
Click OK to apply the changes.
Now you should be able to set the correct file type using Associate with File Type in the context menu.
Limitations
The Docker integration plugin has certain limitations and bugs, however JetBrains is constantly working on fixes and improvements for it. You can find the list of Docker issues in our bug tracking system and vote for the ones that affect you the most. You can also file your own bugs and feature requests.
Phpstorm Run Phpunit In Docker
The term remote PHP interpreter denotes a PHP engine installed on a remote host or in a virtual environment. The term remote PHP interpreter is used as the opposite of local PHP interpreters that are installed on your computer, see Configuring Local PHP Interpreters.
You can access a remote PHP interpreter through SSH, Docker, Docker Compose, Vagrant, or WSL:
By using SSH, you can access a PHP interpreter through the SSH access to the host where the PHP interpreter is installed.
Before you start:
Configure access to an ssh server on the target remote host and make sure this server is running.
Make sure the PHP Remote Interpreter and FTP/SFTP Connectivity plugins are enabled. The plugins are activated by default. If the plugins are disabled, enable them on the Plugins page as described in Manage plugins.
Create an SSH configuration as described in Create SSH configurations.
Configure a PHP interpreter using SSH
In the Settings/Preferences dialog Ctrl+Alt+S, go to PHP.
On the PHP page that opens, click next to the CLI Interpreter list.
In the CLI Interpreters dialog that opens, click in the left-hand pane, then choose From Docker, Vagrant, VM, WSL, Remote... from the popup menu.
In the Configure Remote PHP Interpreter dialog that opens, choose the SSH method.
From the SSH configuration list, choose one of the created SSH configurations, or click and create a new configuration as described in Create SSH configurations.
To use an interpreter configuration, you need path mappings that set correspondence between the project folders, the folders on the server to copy project files to, and the URL addresses to access the copied data on the server. PhpStorm first attempts to retrieve path mappings itself by processing all the available application-level configurations. If PhpStorm finds the configurations with the same host as the one specified in the selected SSH configuration, the mappings from these configurations are merged automatically. If no configurations with this host are found, PhpStorm displays an error message informing you that path mappings are not configured.
To fix the problem, in the Settings/Preferences dialog Ctrl+Alt+S, go to PHP. Click in the Path mappings field and map local folders to the folders on the server.
- In the PHP interpreter path field, specify the location of the PHP executable file in accordance with the configuration of the selected remote development environment.
For remote hosts, PhpStorm by default suggests the /usr/bin/php location.
To specify a different folder, click and choose the relevant folder in the dialog that opens. Note that the PHP home directory must be open for editing.
When you click OK, PhpStorm checks whether the PHP executable is actually stored in the specified folder.
If no PHP executable is found, PhpStorm displays an error message asking you whether to continue searching or save the interpreter configuration anyway.
If the PHP executable is found, you return to the CLI Interpreters dialog where the installation folder and the detected version of the PHP interpreter are displayed.
In the CLI Interpreters dialog, click Show phpinfo to have PhpStorm display a separate information window with the installation details and the list of loaded extensions and configured options. Note that the additional options specified in the Configuration Options field of the PHP Interpreters dialog are not listed.
By using the Docker configuration, you can access a PHP interpreter installed in a Docker container.
Before you start:
Make sure that Docker is downloaded, installed, and configured on your computer as described in Docker.
Make sure the Docker and PHP Docker plugins are installed and enabled. The plugins are activated by default. If the plugins are disabled, enable them on the Plugins page as described in Manage plugins.
Configure the PHP development environment in the Docker container to be used.
Learn more about using Docker with PhpStorm in Docker.
Configure a PHP interpreter in a Docker container
In the Settings/Preferences dialog Ctrl+Alt+S, go to PHP.
On the PHP page that opens, click next to the CLI Interpreter list.
In the CLI Interpreters dialog that opens, click in the left-hand pane, then choose From Docker, Vagrant, VM, WSL, Remote... from the popup menu.
In the Configure Remote PHP Interpreter dialog that opens, choose the Docker method.
Provide the connection parameters:
In the Server field, specify the Docker configuration to use, see Configure the Docker daemon connection settings for details. Select a configuration from the list or click New... and create a new configuration on the Docker page that opens.
In the Image name field, specify the base Docker image to use. Choose one of the previously downloaded or your custom images from the list or type the image name manually, for example,
php:latest
orphp:7.0-cli
. When you later launch the run configuration, Docker will search for the specified image on your machine. If the search fails, the image will be downloaded from the Docker Official Images repository on the Docker Registry page.
- In the PHP interpreter path field, specify the location of the PHP executable file in accordance with the configuration of the selected remote development environment.
For Docker containers, PhpStorm by default suggests the php location.
When you click OK, PhpStorm checks whether the PHP executable is actually stored in the specified folder.
If no PHP executable is found, PhpStorm displays an error message asking you whether to continue searching or save the interpreter configuration anyway.
If the PHP executable is found, you return to the CLI Interpreters dialog where the installation folder and the detected version of the PHP interpreter are displayed.
In the CLI Interpreters dialog, click Show phpinfo to have PhpStorm display a separate information window with the installation details and the list of loaded extensions and configured options. Note that the additional options specified in the Configuration Options field of the PHP Interpreters dialog are not listed.
By using the Docker Compose configuration, you can access a PHP interpreter running in a multi-container Docker Compose environment.
This functionality requires docker-compose version 1.18.0 or later.
Before you start:
Make sure that Docker is downloaded, installed, and configured on your computer as described in Docker.
Make sure the Docker and PHP Docker plugins are installed and enabled. The plugins are activated by default. If the plugins are disabled, enable them on the Plugins page as described in Manage plugins.
Configure the PHP development environment in the Docker container to be used.
Learn more about using Docker Compose with PhpStorm in Using Docker Compose.
Configure a PHP interpreter using Docker Compose
In the Settings/Preferences dialog Ctrl+Alt+S, go to PHP.
On the PHP page that opens, click next to the CLI Interpreter list.
In the CLI Interpreters dialog that opens, click in the left-hand pane, then choose From Docker, Vagrant, VM, WSL, Remote... from the popup menu.
In the Configure Remote PHP Interpreter dialog that opens, choose the Docker Compose method.
Provide the connection parameters:
In the Server field, specify the Docker configuration to use, see Configure the Docker daemon connection settings for details. Select a configuration from the list or click New... and create a new configuration on the Docker page that opens.
In the Configuration file(s) field, specify the docker-compose configuration files to use. The base configuration file located in the project root is selected by default. To select a different file or several files, click and select the desired configuration file in the Docker Compose Configuration Files dialog that opens.
From the Service list, choose the service corresponding to the container the PHP development environment is set up in.
If necessary, in the Environment Variables field, provide the environment variables. See Using Environment Variables for details.
- In the PHP interpreter path field, specify the location of the PHP executable file in accordance with the configuration of the selected remote development environment.
For Docker containers, PhpStorm by default suggests the php location.
When you click OK, PhpStorm checks whether the PHP executable is actually stored in the specified folder.
If no PHP executable is found, PhpStorm displays an error message asking you whether to continue searching or save the interpreter configuration anyway.
If the PHP executable is found, you return to the CLI Interpreters dialog where the installation folder and the detected version of the PHP interpreter are displayed.
In the CLI Interpreters dialog, click Show phpinfo to have PhpStorm display a separate information window with the installation details and the list of loaded extensions and configured options. Note that the additional options specified in the Configuration Options field of the PHP Interpreters dialog are not listed.
- In the Lifecycle area of the CLI Interpreters dialog, choose how the Docker container for the selected service should be managed by PhpStorm.
Always start a new container ('docker-compose run'): choose this option to have the container started via the run command. The container will be restarted upon each run.
Connect to existing container ('docker-compose exec'): choose this option to have the container started once, and then connect to it via the exec command.
By using the Vagrant configuration, you can access a PHP interpreter installed on the corresponding Vagrant instance.
Before you start:
Make sure that Vagrant and Oracle's VirtualBox are downloaded, installed, and configured on your computer as described in Vagrant: Working with Reproducible Development Environments.
Make sure the Vagrant bundled plugin is enabled in the Installed tab of the Settings/Preferences | Plugins page as described in Managing plugins.
- Make sure that the parent folders of the following executable files are added to the system PATH variable:
vagrant.bat or vagrant from your Vagrant installation. This should be done automatically by the Vagrant installer.
VBoxManage.exe or VBoxManage from your Oracle's VirtualBox installation.
Configure the PHP development environment in the Vagrant instance to be used.
Learn more about using Vagrant with PhpStorm in Vagrant: Working with Reproducible Development Environments.
Configure a PHP interpreter in a Vagrant instance
Phpstorm Xdebug Docker
In the Settings/Preferences dialog Ctrl+Alt+S, select PHP.
On the PHP page that opens, click next to the CLI Interpreter list.
In the CLI Interpreters dialog that opens, click in the left-hand pane, then choose From Docker, Vagrant, VM, WSL, Remote... from the popup menu.
In the Configure Remote PHP Interpreter dialog that opens, choose the Vagrant method.
Provide the connection parameters:
Specify the Vagrant instance folder which points at the environment you are going to use. Technically, it is the folder where the VagrantFile configuration file for the desired environment is located. Based on this setting, PhpStorm detects the Vagrant host and shows it as a link in the Vagrant Host URL read-only field.
To use an interpreter configuration, you need path mappings that set correspondence between the project folders, the folders on the server to copy project files to, and the URL addresses to access the copied data on the server. PhpStorm evaluates path mappings from the VagrantFile configuration file.
- In the PHP interpreter path field, specify the location of the PHP executable file in accordance with the configuration of the selected remote development environment.
For Vagrant instances, PhpStorm by default suggests the /usr/bin/php location.
To specify a different folder, click and choose the relevant folder in the dialog that opens. Note that the PHP home directory must be open for editing.
When you click OK, PhpStorm checks whether the PHP executable is actually stored in the specified folder.
If no PHP executable is found, PhpStorm displays an error message asking you whether to continue searching or save the interpreter configuration anyway.
If the PHP executable is found, you return to the CLI Interpreters dialog where the installation folder and the detected version of the PHP interpreter are displayed.
In the CLI Interpreters dialog, click Show phpinfo to have PhpStorm display a separate information window with the installation details and the list of loaded extensions and configured options. Note that the additional options specified in the Configuration Options field of the PHP Interpreters dialog are not listed.
By using WSL, you can access a PHP interpreter installed in a Linux environment through the Windows Subsystem for Linux compatibility layer.
Before you start, make sure the following prerequisites are met:
Phpstorm Docker Phpunit Version Not Installed
On your Windows 10 machine, make sure the WSL feature is enabled, and the preferred Linux distribution is installed. Refer to the Windows Subsystem for Linux Installation Guide for Windows 10 for details.
Inside the Linux installation, make sure PHP is installed. For the detailed installation instructions, refer to Debian GNU/Linux installation notes. If you are using Ubuntu, you can run this command in the Terminal to quickly install PHP:
sudo apt install php php-mbstring php-dom php-xml php-zip php-curl php-xdebug
Configure a PHP interpreter using WSL
In the Settings/Preferences dialog Ctrl+Alt+S, go to PHP.
On the PHP page that opens, click next to the CLI Interpreter list.
In the CLI Interpreters dialog that opens, click in the left-hand pane, then choose From Docker, Vagrant, VM, WSL, Remote... from the popup menu.
In the Configure Remote PHP Interpreter dialog that opens, choose the WSL method.
From the Linux distribution list, choose one of the installed Linux distributions to use.
- In the PHP interpreter path field, specify the location of the PHP executable file in accordance with the configuration of the selected remote development environment.
For WSL, PhpStorm by default suggests /usr/local/bin/php.
To specify a different folder, click and choose the relevant folder in the dialog that opens. Note that the PHP home directory must be open for editing.
When you click OK, PhpStorm checks whether the PHP executable is actually stored in the specified folder.
If no PHP executable is found, PhpStorm displays an error message asking you whether to continue searching or save the interpreter configuration anyway.
If the PHP executable is found, you return to the CLI Interpreters dialog where the installation folder and the detected version of the PHP interpreter are displayed.
In the CLI Interpreters dialog, click Show phpinfo to have PhpStorm display a separate information window with the installation details and the list of loaded extensions and configured options. Note that the additional options specified in the Configuration Options field of the PHP Interpreters dialog are not listed.
Provide additional configuration options
In the Settings/Preferences dialog Ctrl+Alt+S, go to PHP.
On the PHP page that opens, click next to the CLI Interpreter list.
In the Additional area of the CLI Interpreters dialog, you can optionally customize the configuration settings of the PHP installation.
In the Debugger extension field, specify the path to Xdebug. This enables PhpStorm to activate Xdebug when it is necessary if you have disabled it in the php.ini file, see Configuring Xdebug for Using in the On-Demand Mode.
In the Configuration options field, compose a string of configuration directives to be passed through the -d command line option and thus add new entries to the php.ini file. The directives specified in this field override the default directives generated by PhpStorm, such as
-dxdebug.remote_enable=1
,-dxdebug.remote_host=127.0.0.1
,-dxdebug.remote_port=9001
,-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 do that, click next to the Configuration options field, and then create a list of entries in the Configuration Options dialog that opens.
- 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.
- 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.
Configure custom mappings
If you use an interpreter accessible through SSH connection or located on a Vagrant instance or in a Docker container, the mappings are automatically retrieved from the corresponding deployment configuration, Vagrantfile, or Dockerfile.
In the Settings/Preferences dialog Ctrl+Alt+S, go to PHP.
From the Interpreter list, choose the remote interpreter for which you want to customize the mappings. The Path Mappings read-only field shows the path mappings retrieved from the corresponding deployment configuration, Vagrantfile, or Dockerfile. To specify the custom mappings, click next to the Path Mappings field.
The Edit Project Path Mappings dialog shows the path mappings retrieved from the deployment configuration, Vagrantfile, or Dockerfile. These mappings are read-only.
To add a custom mapping, click and specify the path in the project and the corresponding path on the remote runtime environment in the Local Path and Remote Path fields respectively. Type the paths manually or click and select the relevant files or folders in the dialog that opens.
To remove a custom mapping, select it in the list and click .
Phpunit Setup
Switch between configured PHP interpreters on the fly
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 Configure keyboard shortcuts.
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/Preferences dialog Ctrl+Alt+S. This will also affect the run/debug configurations, test frameworks', and quality tools' configurations that are set to use the default project interpreter.