PhpStorm prerequisites

DevBox is currently undergoing an update and is not available for download. A new version will be available in the near future. Please check back for updates.

This topic discusses tasks you must perform before you can use PhpStorm with DevBox.

Find a service port

DevBox randomly assigns ports to services every time a container starts. To use DevBox with PhpStorm, you must know some of these ports (especially the SSH and the web server listen ports).

Determine a listen port

To determine a listen port:

In a command window, find your container identifiers:

docker-compose ps

The command displays the listen ports. An example follows:

docker-compose ps

                         Name                                        Command               State                                                 Ports                                              
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
magento2devbox_db_709831d587f2feef1e27fa41d4e70219        docker-entrypoint.sh mysqld      Up      0.0.0.0:32780->3306/tcp                                                                          
magento2devbox_elastic_709831d587f2feef1e27fa41d4e70219   /docker-entrypoint.sh elas ...   Up      0.0.0.0:32777->9200/tcp, 9300/tcp                                                                
magento2devbox_rabbit_709831d587f2feef1e27fa41d4e70219    docker-entrypoint.sh rabbi ...   Up      15671/tcp, 0.0.0.0:32778->15672/tcp, 25672/tcp, 4369/tcp, 5671/tcp, 0.0.0.0:32779->5672/tcp      
magento2devbox_redis_709831d587f2feef1e27fa41d4e70219     docker-entrypoint.sh redis ...   Up      6379/tcp                                                                                         
magento2devbox_web_709831d587f2feef1e27fa41d4e70219       /usr/local/bin/entrypoint.sh     Up      22/tcp, 0.0.0.0:22->32705/tcp, 44100/tcp, 0.0.0.0:32781->5000/tcp, 0.0.0.0:32782->80/tcp, 9000/tcp

In the preceding example:

  • The database listens on port 32780
  • Elasticsearch listens on ports 32777 and 9300
  • RabbitMQ listens on ports 15671, 32778, 25672, 4369, 5671, and 32779
  • Redis listens on port 6379
  • In the web container, the following ports are used:

    • SSH listens on port 32705

      Applications like PhpStorm communicate with DevBox on the SSH listen port. It’s very important to know this port.

    • Unison synchronization (Windows only) listens on port 32781
    • The web server listens on port 32782

You can use any unmapped ports anyway you like. (An example of an unmapped port is port 9000 in the web container in the preceding example.)

Create an SSH tunnel on Windows

To use Xdebug with Docker on Windows, you must set up an SSH tunnel because Windows doesn’t have a native SSH client.

You don’t need to use a third-party SSH client on Mac OS because it has a native client. Instead, run the m2devbox-debug.sh script before you need to create a tunnel to DevBox. One example of doing this is to run Xdebug.

The following procedure shows an example of creating an SSH tunnel using Putty. You can use other applications (such as Cygwin); for more information, consult the documentation provided with those applications.

To set up an SSH tunnel on Windows using Putty:

  1. If you haven’t already done so, download Putty.
  2. Start Putty.
  3. In the Category pane, click Session.
  4. Enter the following information:

    • Host Name (or IP address) field: Enter 127.0.0.1
    • Port field: Enter the SSH listen port

    Set up Putty

  5. In the Category pane, click Connection > Data
  6. Enter the following information:

    • Auto-login username field: Enter magento2

    Set up Putty

  7. In the Category pane, click Connection > SSH > Tunnels.
  8. Enter the following information:

    • Source port field: Enter 9000
    • Destination field: Enter 127.0.0.1:9000
    • Click Remote
  9. Click Add.

    The following figure shows an example.

    Create an SSH tunnel in Putty

  10. In the Category pane, click Session.
  11. In the Saved Sessions field, enter a name for this SSH tunnel.
  12. Click Save as the following figure shows.

    Save your SSH tunnel

  13. To test the SSH tunnel, click Load, then click Open.

If an “unable to connect” error displays, verify all of the preceding information and try again.

Set the user’s bash profile

This section discusses an optional step of changing to the /var/www/magento2 directory in the DevBox’s user’s bash profile. This means every time you start an interactive session in a command shell, you’re executing commands from that directory.

To set the user’s bash profile:

  1. Open a DOS command prompt (Windows) or Terminal (Mac OS) window.
  2. Enter the following command:

    docker-compose exec --user=magento2 web /bin/bash
    

    This commands opens an SSH shell.

  3. In the shell prompt, enter the following command:

    vim ~/.bash_profile
    
  4. Press i (insert).
  5. Enter the following command in the vim window:

    cd /var/www/magento2
    
  6. Press :wq to save the file and exit vim.
  7. Enter exit to exit the SSH shell and return to your command prompt.

Next step

Set up your PhpStorm project