PHP Remote Interpreters Support in PhpStorm 8 EAP

Support for php_remote_int_introPHP remote interpreters has been introduced in PhpStorm 8 EAP. It lets us use a PHP interpreter over SSH installed on any remote environment, to run/debug application and run testing tools remotely.

Using a remote interpreter instead of a local one gives us an opportunity to get advantages of a PHP interpreter installed in a production-like environment (be it a physical server, a virtualized environment such as Vagrant, or any other). That way we can make sure there will be no inconsistencies when the application is finally deployed to production.

In this blog post we will look into configuring and using PHP remote interpreters for PHPUnit.

PHP Remote Interpreters Configuration

A remote interpreter can be configured in the same way as a local one in Settings | PHP | Interpreter | …

php_remote_int_config1

All the current PHP interpreters will be listed. Click the + button to add a new one, then select Remote to add a new remote interpreter.

php_remote_int_config2

The PHP remote interpreter dialog displays:

php_remote_int_config3

A PHP remote interpreter can be configured:

  • Manually – all the SSH connection details should be provided in the dialog (Host, Port, User name, Auth type, Password, etc);
  • From the deployment server configuration – after selecting a deployment server, all the connection details will be filled in by PhpStorm from deployment server settings. Please note that SFTP deployment with valid mappings should be configured first in Settings | Deployment to have the button Fill from deployment server settings available.
  • From the Vagrant configuration – after selecting Vagrant Configuration Folder, all the connection details will be filled in by PhpStorm from the current Vagrant configuration.

php_remote_int_config4

After you click OK, the connection will be tested and (in case of success) the remote interpreter will be added to the list of PHP interpreters in PhpStorm.

php_remote_int_config5

Please note that a valid deployment server with correct mappings should be configured in any case so that PhpStorm knows what file should be executed on the remote environment.

PHPUnit via SSH

One of the most important use cases for PHP remote interpreters is running PHPUnit tests remotely, and now it’s already possible.

In order to configure a running PHPUnit remotely, just add a new PHPUnit Setting by Remote Interpreter in Settings | PHP | PHPUnit.

php_remote_int_pu1

Select the appropriate remote interpreter in the dialog to proceed:

php_remote_int_pu2

The PHPUnit configuration will be added, and the usual PHPUnit testing workflow will be valid (with PHPUnit configuration through run/debug configurations dialog).

Please note that PHPUnit configuration will be used according to the default PHP interpreter setting for the project. The same PHPUnit configuration can be used for working with local and remote interpreter, it will rely on the default PHP interpreter setting in the project.

Support for PHP remote interpreters is still a work in progress, so please have a look at known and planned issues and take a minute to report any bugs or feature requests to our issue tracker.

Develop with pleasure!
-JetBrains PhpStorm Team

This entry was posted in Cool Feature, Early Access Program and tagged , , . Bookmark the permalink.

33 Responses to PHP Remote Interpreters Support in PhpStorm 8 EAP

  1. Marcel Hernandez says:

    The use of a remote interpreter would make it possible to Xdebug from the IDE unit tests that were running in a Vagrant box, am I right?

    • Mikhail Vink says:

      Well, that’s not only about debugging (remote debugging was possible without remote interpreters), but mostly for running PHPUnit tests on Vagrant, so I suppose the answer is yes, you are right.

      • jimmy says:

        I can now run tests with remote php interpreter, but I can’t start the debug session. from the console, I can see the message:

        ssh://xxxx@192.168.1.19:22/usr/bin/php -dxdebug.remote_enable=1 -dxdebug.remote_mode=req -dxdebug.remote_port=17001 -dxdebug.remote_host=192.168.1.3

        and with the same port and machine, I can use eclipse to debug my web app (not the phpunit tests, that’s why I choose phpstorm:)).

        anything I missed?

  2. Is it somehow possible to either

    * use Mac OS’s keychain for the private key password
    * or use the authentication mechanism of the terminal (which for me is set up to log in into my Vagrant box automatically using my private key and passphrase)

    This would make remote interpreters even more convenient!

    Thanks for a response,

    Mimi

    • Liubov Melnikova says:

      1. Do you mean password manager for Mac?
      2. If you want it to be used automatically from terminal, it’s not possible, unless you can setup private key and passphrase in Vagrant settings.

  3. Rüdiger Scheumann says:

    Is it possible to give detailed informations on how to configure a valid deployment server with correct mappings (using a vagrant vm)? I now tried for hours to get php(unit) running remote and a complete example would be of great help.

    I assume the problem in my case is paths on my host machine not getting mapped to paths on my vagrant box. I get error messages stating “Cannot open file “/Volumes/…”, which is the absolute path on the host and therefore can’t be found in the vm’s filesystem.

    Vardumping $argv in .phpstorm_helpers/phpunit.php shows that $argv[2] (directory containing tests to be executed) is pointing to a directory on my host machine “/Volumes/…/Project” and not to “/home/vagrant/project” on my vagrant box. So I assume the phpunit helper script is okay, but something is wrong with the arguments PhpStorm passes to that helper script. If I ssh into the vagrant box and run phpunit manually, it runs fine.

    Thanks for help!

      • I have exactly the same problem as Rüdiger (and have similarly spent hours trying to get this to work). Unfortunately, the article you linked to doesn’t address this problem at all.

        Please note that PHPUnit configuration will be used according to the default PHP interpreter setting for the project. The same PHPUnit configuration can be used for working with local and remote interpreter, it will rely on the default PHP interpreter setting in the project.

        This seems to suggest that you can set up a new “PHPUnit Run / Debug Configuration”, and it will automatically use the PHP interpreter on the Vagrant box, provided that is the project default.

        The only interpreter in my project is the one on the VM, but the PHPUnit Preferences pane still insists on displaying (and defaulting to) “Local”, and there’s no way of deleting it. I can only assume there’s something else wrong with my configuration, but goodness knows what.

        This post is great, right up until the point at which you gloss over the final few steps, saying “the usual PHPUnit testing workflow will be valid (with PHPUnit configuration through run/debug configurations dialog)”.

        Please provide the missing pieces, so we can get this working.

        Thank you,
        Stephen

      • An update on this…

        I finally got it working through random trial and error. Turns out you must configure the “local” PHPUnit preferences correctly, even though PHPStorm isn’t using them. Quite why this is required is still a mystery to me.

        In my case, I’m using the Laravel framework, so for both the local server and the Vagrant “interpreter”, I needed to specify:

        1. “Use custom loader”: set to vendor/autoload.php (full path locally, and on the server).
        2. “Default configuration file”: set to phpunit.xml (full path locally, and on the server).

        Hopefully this will save somebody else a few hours of flailing about aimlessly.

        Stephen

        • Bob says:

          Hmm, I still can’t seem to get this working.

          When I start a test, PHPStorm tries to run the test on the remote vagrant server, but uses the local path. So the error is:

          bash: line 0: cd: /Users/myname/Sites/ProjectName/public/protected: No such file or directory

          While it should offcourse use:
          /var/www/ProjectName/public/protected

          Any ideas? Am I missing something?

          • Maxim Kolmakov says:

            Bob, you need to configure the valid SFTP deployment server with correct mappings in Settings->Deployment. PhpStorm will use those mappings to translate your local path to remote one.

          • Ryan Castle says:

            For vagrant, hacking on the SFTP deployment settings (instead of “In Place”) worked for me too eventually. Although the setup is different than how it would be for a regular deployment. I’ve spent a whole day on various options. I suppose the docs will improve with a full release.

            I think there are also some places where instead of choosing the built-in vagrant install you have to choose your SFTP server. For instance, in the “Remote Interpreter” setup choose “Deployment configuration” instead of “Vagrant” (and pick the SFTP deployment you created).

            Also PHPUnit paths to “phpunit.phar” and to “phpunit.xml” need to refer to the counterparts inside vagrant.

        • happy time says:

          This worked!!! thx

  4. Miikka Virtanen says:

    Is it possible to use remote interpreters for running Composer? I’d like to run Composer on my local VM that has a shared folder to the project root.

  5. Pingback: PHPUnit on Vagrant VM with Remote PHP Interpreter in PHPStorm for MAC

  6. Steve W. says:

    Is this feature limited to PHPStorm? I’m using IDEA 13.1.3 with the PHP plugin version 134.1456 and the “add” context menu in the Interpreters window only shows “Other Local…” as an option. Is there another plugin that I’m missing, or a confiugration setting that is preventing this from showing?

  7. If you cannot find the by remote interpreter option on a mac lion system. Try to scroll. The options bar only one option and does not show a scroll bar. Try to scroll anyway and the option appears magically :-)

  8. Pingback: Using Behat in PhpStorm | JetBrains PhpStorm Blog

  9. Martin says:

    Is there any plan to add this feature to Webstorm? I am running node app inside of Vagrant and it would be nice to ssh into box..

  10. Ricardo says:

    Hi,

    I’m trying to set this up with the latest version of PHPStorm 8 EAP but as soon as I end the connection configuration (both vagrant and manual methods) phpstorm gets stuck trying to connect and it never comes back, I have to then kill the java process. Is this feature broken?

  11. Tim Bezhashvyly says:

    This tutorial missing the final section (scrieenshot). Once everything is configured how do you run the test remotely?

  12. Pingback: PhpStorm 8 released: Blade, Behat, WordPress, Remote PHP interpreters, multiple carets/selections, and more | JetBrains PhpStorm Blog

  13. Pingback: PhpStorm 8 发布,PHP 集成开发环境 | 服务器维护

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">