Skip to end of metadata
Go to start of metadata

Redirection Notice

Icon
This page will redirect to https://www.jetbrains.com/help/phpstorm/meet-phpstorm.html in about 2 seconds.

 

Pantheon is a hosting platform, providing best practices for developing, hosting and maintaining Drupal and WordPress web applications. It provides hosting, database, caching, version control, development, staging, test and production environments, backups and workflows for moving an application through the development pipeline.

In this tutorial, we'll take a look at how we can use PhpStorm to develop Drupal and WordPress applications on Pantheon.

If you prefer a video over a tutorial, here's a quick introduction to using PhpStorm and Pantheon.

Getting Started

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.

Icon

When working with Drupal sites, the Pantheon Terminus Command-Line Tool can be used to commit site changes to Pantheon as well, using the pantheon-site-commit.

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.

Icon

Check the Version Control Systems Support in PhpStorm tutorial for more information about PhpStorm's support for version control systems like Git.

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 ssh://codeserver.dev.someguid@codeserver.dev.someguid.drush.in:2222/~/repository.git.

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 /code to 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.

Icon

By default, only files changed by the IDE will be uploaded. If files are changed by some other process such as transpilation of Sass or LESS, a File Watcher, or Grunt, they are not automatically uploaded. To change this behavior and autoupload these changes as well, enable the Upload external changes option.

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.

Drupal

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.

Drush Integration

Drush is a command line shell and scripting interface for Drupal. We can configure Drush as a PhpStorm command line tool and get full support for invoking Drush commands from the command line tools.

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.

Icon

To use Drush on Pantheon sites, it is recommended to install the Pantheon Drush aliases. These allow executing Drush commands against a Pantheon site.

For example, calling drush @pantheon.sitename.envwatchdog-show (as explained here) will watch events like warnings and errors from the site as they happen.

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.

WordPress

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:

Icon

PhpStorm does not ship with database drivers installed, but it does provide a handy way of downloading them when needed: click the "Download ... driver files" link next to the warning about missing drivers to download them.

After testing and saving the database connection details, we can explore, manage, refactor, query and code against our Pantheon database.

Icon

To learn more about Databases and SQL Editor in PhpStorm, check this tutorial.

 

  • No labels