- Getting Started
- Enabling Framework Integration
- Managing the Pantheon Database with PhpStorm
If you prefer a video over a tutorial, here's a quick introduction to using PhpStorm and Pantheon.
For this tutorial, we'll assume a site has already been created on Pantheon. A tutorial is available in the Pantheon docs explaining how to create a site.
Pantheon provides two ways of working with the platform. We can connect using Git, develop locally and push changes to Pantheon once we want them to go live. The other way of working is using SFTP where we deploy our changes on the Pantheon servers directly, either manually or automatically. PhpStorm supports both modes, let's see how we can work with them.
Getting Started with Pantheon Git Mode
When working with Pantheon's Git Mode, we can use PhpStorm to commit, push and pull changes from our site.
Cloning the Pantheon Git repository
From the PhpStorm welcome screen, use the Checkout from Version Control | Git option (or use the VCS | Checkout from Version Control | Git menu). We can enter our Pantheon's Git repository details, which are found on our site's dashboard, in the dialog that opens. The Git URL typically looks similar to
After selecting the local path we want to clone into and clicking OK, PhpStorm will prompt for a password. We can enter our Pantheon password and let PhpStorm finish cloning. If the site that has been cloned is a Drupal or WordPress site, PhpStorm will offer framework integration suggestions.
Making a Change and Committing to Pantheon
We can work on our website in PhpStorm. All changes made can be committed to Git. We can do this using the Ctrl+K keyboard shortcut (CMD+K on Mac OS X). PhpStorm will present us with a dialog where we can review the changes we made and add a description to the commit.
Before committing, PhpStorm can perform several additional actions for us, like reformatting code, optimizing imports, check if there are TODO comments in our code and run code analysis.
Clicking the Commit button will provide us with the choice of just committing changes to the local Git repository on our machine, or do a Commit and Push which will also push our changes back to Pantheon so they can be deployed.
Once pushed, the Pantheon site dashboard will display the commit in our commit log and deploy the changes to the dev environment from where we can propagate them to other environments using the Pantheon Workflow.
Getting Started with Pantheon SFTP Mode
Pantheon lets us develop our code using SFTP where we deploy our changes on the Pantheon servers directly, either manually or automatically. Let's see how we can get our site copied to our machine so we can start working on it.
Creating a Project using SFTP
From the welcome screen, select the Create New Project From Existing Files option. Alternatively, use the TODO menu.
In the next screen, select the Web server is on remote host, files are accessible via FTP/SFTP/FTPS option.
Once selected, we can continue the wizard. In the deployment options screen, pick Default. Next, add a new server and enter the details found in the Pantheon site dashboard. The following options must be provided:
- Server type set to SFTP
- SFTP host: from the site dashboard
- Port: 2222
- Username: from the site dashboard
- Password: your Pantheon password
- Root path: click Autodetect, then add
/codeto the end of the detected path
The Web server root URL can be set to the full website URL we're working on. Here's an example of what these settings could look like.
In the Choose Remote Path dialog, click the Project Root button to mark the entire folder as belonging to our project.
Once we finish the wizard, PhpStorm will download the existing site's files and open the project. If the site
is a Drupal or WordPress site, PhpStorm will offer framework integration suggestions.
Deploying Local Changes to Pantheon using SFTP
Since Pantheon's SFTP mode encourages on-server development, it's good practice to open PhpStorm's settings and under Build, Execution, Deployment | Deployment | Options set Upload changed files automatically to the default server to Always. This will ensure that PhpStorm always uploads changes that were made locally directly to the Pantheon server.
If it's preferred to upload changes manualy, check the Sync changes and automatic upload to a deployment server in PhpStorm tutorial for more information about the various options.
Once we've made some changes, we can commit them using the site dashboard.
Exploring the Site Filesystem
PhpStorm comes with drag & drop as well as copy & paste support from the project pane to the Remote Host tool window. To be able to use this, open the Remote Host tool window using the Tools | Deployment | Browse Remote Hosts menu.
Files and folders can be copied (or moved) from and to the deployment server using drag-and-drop. This functionality behaves like it does on our computer: by default, the selected item will be moved. When holding the Ctrl key when dropping, the file or folder will be copied instead.
Enabling Framework Integration
Pantheon focuses on Drupal and WordPress development, two frameworks fully supported by PhpStorm. Once a project has been downloaded to a developer machine, the IDE will recognize the application type and propose enabling framework-specific support. Let's see.
Once a Drupal project has been downloaded from Pantheon, the IDE offers us to enable Drupal integration.
Clicking Enable will let us specify the full path to a Drupal installation. This is used to provide code completion hints while developing. We also have to specify the Drupal version. Supported versions are Drupal 6, 7 and 8.
We can optionally also enable the Drupal code styles, another suggestion the IDE will offer us.
Once done, PhpStorm provides many features like hook completion and navigation, #Drush Integration, searching in the Drupal API documentation, Coder and PHP Code Sniffer support, and many more features that are available in PhpStorm. Check the Drupal Development using PhpStorm tutorial to learn more about the possibilities.
Once configured, we can bring up the command line tool window by selecting Tools | Run Command... or pressing Ctrl+Shift+X (Cmd-Shift-X on Mac OS X). It provides completion for all possible commands offered by the tool.
Pantheon Terminus Command-Line Tool Integration
The Pantheon Terminus Command-Line Tool can be installed into our site and executed with Drush. After installing Terminus, open the PhpStorm settings and refresh the Drush command line tool commands list from the Tools | Command Line Tools Support section. Once done, the Drush command line tool completion in PhpStorm will provide all Pantheon-specific commands. We can execute them from within the IDE.
Once a WordPress project has been downloaded from Pantheon, the IDE offers us to enable WordPress integration.
Clicking Enable will let us specify the full path to a WordPress installation. This is used to provide code completion hints while developing, for example to hooks defined in the various plugins and WordPress base functionality.
Once done, the IDE offers us to enable WordPress code style. We can enable it and continue development.
PhpStorm provides many features like hook completion and navigation, searching on WordPress.org, WordPress Command Line Tool WP-CLI Integration, PHP Code Sniffer integration and many more features that are available in PhpStorm. Check the WordPress Development using PhpStorm tutorial to learn more about the possibilities.
Managing the Pantheon Database with PhpStorm
Every Pantheon site comes with a database, which we can manage from within PhpStorm. The IDE can help us perform all types of routine database tasks, such as querying for a record; checking what that column was named again; database development where we have to create the schema structure and more. PhpStorm also provides code completion on table names and columns, while writing PHP code!
All we have to do is setup a connection to our Pantheon database. From the View | Tool Windows menu, open the Database tool window and use the green + icon in the toolbar to create a new data source. Pick Data Source | MySQL as the database type. PhpStorm will ask us for connection information, which we can find on the Pantheon site dashboard. Here's an example configuration:
After testing and saving the database connection details, we can explore, manage, refactor, query and code against our Pantheon database.