Skip to end of metadata
Go to start of metadata

There are many ways to transfer project files with their copies on the deployment server. This tutorial describes how to automatically upload changes with a deployment server using PhpStorm, for example when a debugging session is started or changes are committed to VCS. It builds on Deploying PHP applications with PhpStorm.

0. Prerequisites

A deployment server has been configured as described in Deploying PHP applications with PhpStorm.

1. Synchronize your changes

Next to uploading and downloading files from and to a deployment server, PhpStorm can also synchronize changes. To do this, use the context menu on any file or folder or the entire project and use the Deployment | Sync with Deployed to <server name>... context menu. This will trigger a diff between the PhpStorm project and the remote server.

By default, the diff will be based on file contents. Optionally this can be changed from the toolbar to compare files based on size and/or timestamp.

From this diff, we can select what will happen to the selected files. We can select to either download or upload changes from the project to the deployment server by using the context menu.

If only specific changes to a file have to be synchronized from the deployment server to the PhpStorm project, this can be done using the differences view, cherry-picking changes that have to be replicated. Only remote changes can be partially applied to local project, not vice-versa.

Once diff actions have been set, we can use the toolbar icons to Synchronize Selected or Synchronize All.

(optional) 2. Automatic Upload

Prerequisite: The deployment server has been set as the default server for the project. This can be done from the Project Settings | Deployment, selecting the server and using the toolbar button to make it the default.

When a user needs to have the exact same files on the server as in the PhpStorm project, automatic upload can be of help. Automatic upload means that whenever a change is saved in the IDE, it will be deployed to the deployment server. Configuration is done through Project Settings | Deployment | Options, setting the Upload changed files automatically to the default server option to Always or On explicit save action.

  • Always will do as it says and upload files whenever they are saved or autosaved. This is not recommended for deployment to production: incomplete code can be uploaded while developing, potentilly breaking the production application.
  • On explicit save action will only upload when a file save was invoked manually by choosing File | Save all or by using the keyboard shortcut Ctrl+S (Cmd-S on Mac OS X)

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

Whenever automatic uploadoccurs, the File Transfer tool window will inform us about this:

(optional) 3. Automatic Upload before launching a debugging session

When working on a PHP application, we can have our source code automatically uploaded to a deployment server every time we run the application or initiate a debugging session from our IDE. This can be very useful when working with a development web server, for example, because when we run our debug our application remotely it will always be with the latest source code we have in our project.

From a Run/Debug Configuration, we can add a launch action to Upload files to Remote Host.

Next, we can specify which folders should be uploaded to the deployment server. This can be the full project, or a subfolder that is specific to the Run/Debug Configuration.

(optional) 4. Automatic Upload on VCS commit

PhpStorm can automatically upload files that are committed to VCS from the Commit Changes window. The target server can be specified and when the Always use selected server option is checked, uploads to the deployment server will always be executed on commit.

(optional) 5. Notify about remote changes

When working on the local project and the remote server, we may want to receive notifications if changes are made remotely. We can configure this in Project Settings | Deployment | Options.

There are two settings that must be enabled to get notifiations about remote changes:

  • Warn when uploading over newer file lets us select if we want to be warned about overwriting files on the deployment server. By default this option is turned off, but we can choose to compare files based on either timestamp and size or the actual file contents. We will need one of these comparisons enabled before we are able to turn on change notifications. The reason for this is PhpStorm has to know when a file is considered changed.
  • Notify about remote changes is what we are after: when enabled, we will get notified about remote changes that are not in our local project.

If we open a file in the IDE which ahs been changed on the deployment server, we will get a notification about this. We can then merge the changes into our local file or simply choose to overwrite local changes by downloading the remote file.

If you need help troubleshooting deployments, check out the Troubleshooting Deployments in PhpStorm tutorial.

Labels:
None
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.