Set up your PhpStorm project
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 how to set up a PhpStorm project to work with Magento DevBox.
PhpStorm notes:
- The instructions in this topic are based on PhpStorm version 2016.3.2. If you use a different version, some steps might be different. Consult your PhpStorm documentation for details.
-
PhpStorm has a commonly used window that has a different name in Windows and Mac OS:
- Windows: The window is named Settings and you access it by clicking File > Settings.
- Mac OS: The window is named Preferences and you access it by clicking PhpStorm > Preferences.
If you have already set up a PhpStorm project, you can skip this topic and continue with:
Prerequisites
Before you continue, complete the tasks discussed in PhpStorm prerequisites.
Set up your PhpStorm project
This section discusses how to set up a new PhpStorm project to work with Magento DevBox.
Create the project from existing files
To set up a new PhpStorm project to work with Magento DevBox:
- Start PhpStorm.
-
Click File > New Project from Existing Files.
The Create New Project: Choose Your Scenario dialog box is displayed as follows.
-
Click Source files are in a local directory, no Web server is yet configured and click Next.
For a description of other options, consult the PhpStorm documentation.
-
In the Create New Project: Choose Project Directory dialog box, browse to locate the
<DevBox root folder>/shared/webroot/pub
folder.Sample path on Windows:
C:\magento\build-18c4e4d3c5a541f37e9cffd35f1bf74e\build-18c4e4d3c5a541f37e9cffd35f1bf74e\shared\webroot\pub
Sample path on Mac OS:
/Users/me/build-18c4e4d3c5a541f37e9cffd35f1bf74e/shared/webroot/pub
The following figure shows an example.
- Click Project Root and click Finish.
- Wait while PhpStorm indexes the project.
Add a remote PHP CLI interpreter
This section discusses how to add a remote PHP 7 CLI interpreter.
-
In your PhpStorm Settings window, do one of the following:
- Mac OS: Click PhpStorm > Preferences.
- Windows: Click File > Settings.
- In the left pane of the Preferences (Mac OS) or Settings (Windows) window, click Languages & Frameworks > PHP.
- From the PHP Language Level list, click PHP 7.
-
Click next to the CLI Interpreter list.
The CLI Interpreters window is displayed.
- Click (Add).
-
From the Select Interpreter Path list, click Remote as the following figure shows.
-
In the Configure Remote Interpreter dialog box, click SSH Credentials as the following figure shows.
-
Enter the following information:
- Host: Enter
127.0.0.1
- Port: Enter the web container’s SSH listen port.
- Username: Enter
magento2
- Password: Leave blank
- Save password: Select the check box
- PHP executable: Enter
/usr/local/bin/php
- Host: Enter
-
In the Configure Remote PHP Interpreter dialog box, click OK.
If the connection is successful, a confirmation dialog box similar to the following is displayed:
If an error displays, review the preceding information, make sure you know the correct SSH listen port, and try again.
- Follow the prompts on your screen to save your changes.
Create the Xdebug remote host
Adding an Xdebug remote host makes debugging easier because it happens automatically every time you start the DevBox container.
To create the Xdebug remote host:
-
In your CLI Interpreters dialog box, in the General section, click Refresh as the following figure shows.
-
In the Additional section, click next to the Configuration options field as the following figure shows.
- In the Configuration Options dialog box, click (Add).
-
Enter the following information:
- Configuration Directive field: Enter
xdebug.remote_host
- Value field: Enter
127.0.0.1
- Configuration Directive field: Enter
-
In the Configuration Options dialog box, click OK.
Make sure the option and value display as follows.
- If the name and value are displayed, click OK.
If both name and value do not display, click Refresh in the General section and try again.
Add path mappings
Because Magento uses symlinks, you must create path mappings so PhpStorm can properly locate files.
To add path mappings:
- In your PhpStorm Settings window, click Languages & Frameworks > PHP.
- In the right pane, from the CLI Interpreter list, click the name of the DevBox remote CLI interpreter.
-
In the right pane, next to the Path Mappings field, click .
The following figure shows an example.
The Edit Project Path Mappings dialog box is displayed.
- In the Edit Project Path Mappings dialog box, click (Add).
- In the Local Path row, click (Browse) to locate your DevBox project root directory and click Open.
-
In the Remote Path field, enter
/var/www/magento2
The following figure shows an example.
- In the Edit Project Path Mappings dialog box, click OK.
Set up PHPUnit
To set up PHPUnit:
- In your PhpStorm Settings window, expand Languages & Frameworks > PHP > PHPUnit.
-
In the right pane, click Use Composer autoloader as the following figure shows.
- In the Path to script field, click (Browse).
-
Browse to locate
<PhpStorm project root>/vendor/autoload.php
Sample path on Mac:
/Users/me/Downloads/build-18c4e4d3c5a541f37e9cffd35f1bf74e/shared/webroot/vendor
Sample path on Windows:
C:\magento\build-18c4e4d3c5a541f37e9cffd35f1bf74e\build-18c4e4d3c5a541f37e9cffd35f1bf74e\shared\webroot\vendor
- Click Open.
- In the Preferences window, click OK.
Set up PHPUnit to use the remote CLI interpreter
- In your PhpStorm Settings window, expand Languages & Frameworks > PHP > PHPUnit.
- In the center pane, click (Add).
-
From the list, click By remote interpreter as the following figure shows.
- From the Interpreter list, click the name of the DevBox remote CLI interpreter.
-
Click OK as the following figure shows.
- In the Settings window, click OK.
Set up a PHP server
To set up a PHP server for debugging:
- In your PhpStorm Settings window, click Languages & Frameworks > PHP > Servers.
-
In the center pane, click (Add).
The following figure shows an example.
-
Enter the following information:
- Name: Enter a name to identify your server
- Host:
127.0.0.1
- Port: Enter the SSH listen port
- Select the Use path mappings check box.
- Debugger: Click Xdebug
-
Specify path mappings:
- In the File/Directory column, make sure your project root is selected.
- In the Absolute path on the server column, click (Edit) and enter
/var/www/magento2
- Click OK.