Docker Remote Interpreters
PhpStorm 2016.3 gives a much easier way to configure a Docker remote interpreter, with configuration done from an extra config option in the Interpreters pane of the IDE.
It’s previously been possible to work with a container based remote interpreter within PhpStorm, but the configuration was painful using the SSH settings, and it didn’t play well with all of the IDE’s features. In PhpStorm 2016.3, Docker interpreters become a first-class citizen.
Firstly, you’ll need to have a valid Docker configuration. If you are running your host on OSX and using Docker for Mac (as opposed to Docker Machine) then you’ll need to install an extra piece of software — you can find the instructions here. Once you have your Docker configuration setup, we can add the remote interpreter.
We can add a new interpreter from the preferences pane, by selecting Languages & Frameworks, then PHP, and clicking the […] button next to the interpreter drop down. Next, we click the [+] button to add a new interpreter and select Remote.
You can see that the new Docker option added. Once we’ve selected that, we need to pick the Docker configuration (it’s already configured it as mentioned above), and then the image name we wish to use for the container that has our PHP install, plus the path on the container to find the PHP executable.
Note: While just `php` will work fine in some cases, there have been reports that the full path to the PHP executable is needed. You can find this out by running the docker command `docker-compose run php which php` in the directory that your `docker-compose.yml` file is located where `php` is the container name. If you use another docker tool, substitute the `docker-compose` for that tool’s name.
Once we’ve clicked OK, you should see the new interpreter configured correctly and available to select. It’s worth giving it a more descriptive name (and I make it Visible for only this project as containers are usually project based).
Once PhpStorm has picked up your Docker settings, you’ll see the PHP version updating as PhpStorm runs some commands on the container to infer the configuration. Now that the remote interpreter is specified, we can also add the local path on the container to the Xdebug file so that we can step debug our command line scripts using the Xdebug On-Demand tool.
Now that we have the remote interpreter configured, we can use it as usual in any of the places we’d typically set an interpreter, including our test runner (PHPUnit, PhpSpec, Behat), code quality tools (PHPCS and PHPMD), and as previously mentioned, debugging. Let’s configure our PHPUnit test suite to run using this newly supplied Docker container.
We need to tell PhpStorm which interpreter and how to find PHPUnit for this project, we can do that in the PHPUnit settings pane, found under Languages & Frameworks, PHP, PHPUnit. You may already have a configuration here (if you’ve previously been running the unit tests locally, for example), but we need to create a new configuration by clicking the [+] and selecting By Remote Interpreter and then picking the interpreter we configured earlier.
Because PHPUnit is installed here using composer, I can just tell PhpStorm where to find the Composer autoloader as a local path on the container. Notice how we have a mapping from the project root to `/opt/project`. Now we can click OK, and add a run configuration for PHPUnit by clicking the Edit Configurations option from the Run dropdown menu. We can add a new configuration using the [+] button, and selecting PHPUnit.
I like to use the configuration file to define test scope, so I’ve chosen Defined in the configuration file and used an alternate configuration file than the default, but you can do whatever you usually do here. Note that paths in this dialogue are relative to the host machine — not the container. Now, we can save the settings and run the test runner using the green play icon. Hopefully, everything is green.
Docker is an incredible innovation in using containers for development and deployment, and hopefully, these changes in PhpStorm open the door to being able to quickly develop and test your codebase against multiple versions of PHP easily. Try it yourself, and let us know what you think.
— Gary and the PhpStorm Team
Subscribe to Blog updates
Thanks, we've got you!
Qodana Clone Finder: Early Access Program
In December 2020, we announced the EAP for Qodana, which is rapidly evolving into a comprehensive platform that allows companies to perform multi-level evaluations of the quality of code they own, contract, or purchase. Qodana helps you detect bugs without relying on an IDE, either on a local machi…
PhpStorm 2020.2 EAP #3
The Early Access Program for PhpStorm 2020.2 is in full swing and today we’ve got the third build of the 2020.2 EAP for you. In this blog post, you can read about improvements for Git installed in WSL2 and Search Everywhere. Download PhpStorm 2020.2 EAP (more…)…
PhpStorm 2019.3.3 Preview
We’ve just rolled out a preview for the third minor update for PhpStorm 2019.3. Please give the PhpStorm 2019.3.3 Preview build 193.6494.5 a try and share your feedback with us. (more…)…
How to Upgrade to PHP 7.4 with PhpStorm
Check out our fresh video with a few nice tips and tricks on how to update your codebase to PHP 7.4. It combines materials from the PhpStorm 2019.2 and PhpStorm 2019.3 releases, with a few cool bonuses to boot. Nikita drew our attention to the fact that setters are slower than assigning prop…