PhpStorm 2018.2 Help

Tutorial: Deployment in PhpStorm

This tutorial aims to take you step-by-step through configuring an managing deployment of your code to remote hosts, using PhpStorm.

Configuring a deployment server

Click Settings/Preferences icon on the main toolbar or press Ctrl+Alt+S to open the Settings/Preferences dialog, and choose the Deployment page (you can access the same page by choosing Tools | Deployment | Configuration on the main menu).

Click Add item, then in the Add Server dialog box, type your server name (MyRemoteServer) and select its type (in our case, this is Local or mounted folder):

Add server dialog

OK, the new server is added, but it is still void... It only shows the Web server root URL http://localhost, where you will actually browse your uploaded files.

What is specified in the Connection tab?

Select the directory where the project files will be uploaded. In our case, this is the /Applications/MAMP/htdocs local folder. You can either type the path manually, or press Shift+Enter to open the Select Path dialog.)

Deployment Connection Tab

What is specified in the Mapping tab?

Next, switch to the Mappings tab. By default, the Local path field contains the path to the project root. However, you can select any other directory within your project tree. Let's assume the default value.

In the Deployment path field (which is by default empty), specify the folder on your server, where PhpStorm will upload data from the folder specified in the Local path field (in this example, it's ). This path is specified relative to the folder myApp). This path is specified relative to the folder /Applications/MAMP/htdocs.

And, finally, let's accept the default / value for Web path:

Deployment Mapping Tab

OK, apply changes, and the server is ready to use.

Browsing remote hosts

To make sure your server is up and running, select Tools | Deployment | Browse Remote Host in the main menu, and the Remote Host tool window appears on the right of the PhpStorm window:

Remote Hosts tool window

Deployment tools

Next, let's perform some actions, and see what happens.

Uploading

First, let's upload one of the files to the remote server.

In the Project Tool Window, right-click a file you want to upload. In our case, let it be the header.php file. On the context menu, choose Upload to MyRemoteServer, and see the upload results.

Deployment upload

You can also upload contents of each directory within your project. For example, right-click the parent directory of the, namely, src header.php and choose Deployment | Upload to MyRemoteServer from the context menu. We now have the entire directory uploaded to the server:

Deployment File Transfer

Comparing remote and local versions

There is a local and a remote copy of the header.php file, and they are identical. Let's modify the local version.

Modify source

OK, now we've changed the local version. Let's make sure PhpStorm knows about these changes. To do that, again go to the Remote Host Tool Window tool window, and right-click. On the context menu, choose Compare with Local Version. PhpStorm opens the differences viewer, where you can accept changes or reject them, using the buttons Insert from left icon, Insert from right icon, Insert below from left icon, Insert below from right icon, Reject icon:

Diff viewer

Downloading

In the Remote Host Tool Window tool window, right-click the file, and choose Download from here in the context menu. PhpStorm shows a warning:

Deployment download warning

Click Yes:

Deployment download file transfer

You can also download an entire directory, if it has been previously uploaded to the server. For example, if you click the parent pub directory and choose the same command, all nested files will be downloaded from the server.

Synchronizing changes

Make a preliminary step - rollback the changes to the header.php file (Ctrl+Z).

Next, click header.php, and in the main menu choose Tools | Deployment | Sync with Deployed to MyRemoteServer:

Deployment sync

PhpStorm shows differences viewer, where you can accept individual changes or reject them, using the buttons Insert from left icon,Insert from right icon, Insert below from left icon, Insert below from right icon,Reject icon.

Automatic upload to the default server

When you need to have the exact same files on the server as in a PhpStorm project, automatic upload can be of help. Automatic upload means that whenever a change occurs in the IDE, it will be deployed to the default deployment server.

Defining a server as default

A deployment server is considered default if its settings apply by default during automatic upload of changed files. To define a deployment server as the default one, follow these steps:

  1. Choose the desired server on the Deployment page (in our case, MyRemoteServer). You can open this page it two possible ways: either Settings/Preferences | Build, Execution, Deployment | Deployment, or Tools | Deployment | Configuration on the main menu.

  2. Click icon_use_web_server_configuration_as_default.

Enabling automatic upload

As soon as the default server is set, you can make upload to this server automatic. This can be done in the following two ways:

  • Open the deployment Options (Settings/Preferences | Deployment | Options or Tools | Deployment | Options on the main menu), and in the Upload changed files automatically to the default server field choose Always, or On explicit save action. The difference between these two choices is explained in the field description.

  • In the main menu, select Tools | Deployment | Automatic upload. Note that automatic upload in this case is performed in the Always mode.

It is worth noting that the Always mode is not recommended for deploying to production: incomplete code can be uploaded while developing, potentially breaking the production application.

By default, PhpStorm uploads only the files changed by itself. If the files are changed by some other process, such as a VCS branch change, compilation 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:

Upload external changes

Summary

Congrats! You've passed this very basic tutorial and performed the following tasks:

  • Created and configured a server of your own.

  • Uploaded and downloaded files and folders.

  • Compared local and remote versions.

  • Configured the server as default.

  • Enabled automatic upload of external changes.

Last modified: 10 October 2018

See Also