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 copy local changes to the remote server (Copy to Right) or copy changes from the remote server (Copy to Left) using the context menu.
Once diff actions have been set, we can use the toolbar icons to Synchronize Selected or Synchronize All.
(optional) 2. Automatic Upload
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)
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.