Skip to end of metadata
Go to start of metadata

This tutorial describes how to get started with deploying PHP applications with the PhpStorm IDE. We will see what deployment is and how to set up a simple deployment in PhpStorm.

When developing applications with PhpStorm, chances are development happens in one of the following ways. Note other configurations are possible too, but these are the most common.

  • A web server is installed on the local computer. The PhpStorm project sources are under the server document root. In essence, development is happening on the web server.
  • A web server is installed on the local computer. The PhpStorm project sources are stored in another folder. Development happens in PhpStorm, files are copied to the server document root to test things out.
  • A web server is installed on another computer. The PhpStorm project sources are stored on the local computer. Development happens in PhpStorm, files are copied to the server document root using FTP, SFTP, FTPS or using a network share.

In any of these situations, PhpStorm distinguishes the project from the server. To work with the server (e.g. to copy or synchronize files), a deployment server should be configured. Let's have a look at the steps involved.

0. Prerequisites

Depending on how deployment is done, make sure that connectivity between the local computer and the remote host is available. FTP, SFTP, FTPS or file share access must be available.

1. Configuring a deployment server

1.1. Creating a deployment server

Creating a deployment server can be done through the Project Settings | Deployment (or Tools | Deployment | Configuration...). Clicking the green + toolbar button allows us to add a new server.

Give the server a name and select the server type. This can be any of the following:

  • FTP - connect to the deployment server using FTP.
  • FTPS - connect to the deployment server using FTPS.
  • SFTP - connect to the deployment server using SFTP.
  • Local or mounted folder - the deployment server's document root is accessible either as a local folder on our computer, or as a mounted folder on a remote computer.
  • In place - the PhpStorm project is located directly in the local webserver's document root.

Click OK to add the deployment server.

While deployment servers are configured under project settings, their connection details are global and available to any project opened in PhpStorm. Mappings and Excluded Paths are project-specific settings. This way, multiple projects can share the same deployment server without having to configure the connection for each of them separately.

1.2. Configure the connection

From the Connections tab, we now have to specify connection details. Depending on the server type selected earlier, these settings will differ.

One setting is common to all server types: which is the Web server root URL? This will typically be the web URL to the document root.

Expand the below topics to see how to configure the web server based on its type.

FTP, FTPS, SFTP

Expand...

For FTP, FTPS and SFTP servers the configuration is more or less similar. We will have to specify the FTP(S) hostname, port, root path (the path on the remote server which will be used as the root) and credentials.

The Advanced options... button can be used to configure additional connection options. Typically this is not needed, but if for example passive mode is required or the number of concurrent connections has to be limited, these options can be specified.

Using the Test FTP connection... button, we can validate the settings entered:

Local or mounted folder

Expand...

For a local or mounted folder, we have to specify the path to where project files are to be deployed:

In place

Expand...

For in-place servers, we only have to specify the web server root URL. The reason for this is that an in-place server is expected to have its document root mapped to our PhpStorm's project root, so files don't have to be transferred.

1.3. Configure mappings

A mapping is the relation between the project folders, the folders on the server to copy project files to, and the URLs to access the data on the server over HTTP. These mappings are used to help PhpStorm find a file or folder in our project or on the remote server.

The easiest way is to map the entire project root folder to a folder on the server, where the project folder structure will be identical on the server. Depending on the server configuration and project layout, it may be useful to specify one or more mappings through the Mappings tab.

In the screenshot below, we're specifying the following relations:

Local path Deployment path (e.g. path on FTP server) Web path (URL)
C:\Projects\wordpress-networkmarketing
/site/wwwroot/wp-content/plugins/jetbrains-networkmarketing
/wp-content/plugins/jetbrains-networkmarketing

Frameworks like Symfony2, Zend Framework, Laravel or CakePHP typically make use of two main folders: /application in which controllers and application code lives, and /public which corresponds to the server's document root and typically serves JavaScript, CSS and so on. This type of application could be mapped as such:

Local path Deployment path (e.g. path on FTP server) Web path (URL)
C:\Projects\MyProject\application
/site/application
 
C:\Projects\MyProject\public
/site/wwwroot
/

This can also be configured in PhpStorm:

Note the warning shown is because the /application path has no web path specified, which in this setup is perfectly fine.

Note that when folders match multiple relevant mappings, the nearest one is applied.

1.4. (optional) Set the default server

If only one deployment server is in use or PhpStorm typically is used to deploy to one server, it may make sense to set it as the default one. Setting a server as the default for a project can be done from the Mappings tab using the Use this server as default button.

1.5. (optional) Configure excluded paths

Sometimes there are paths that should not be uploaded to the server, or downloaded to the local project when performing a deployment. For example a log file directory, or a directory containing cached Smarty templates. These paths can be easily excluded from the Excluded Paths tab.

2. Exploring the server

After configuration, we can browse the remote server using the Tools | Deployment | Browse Remote Hosts menu. This will open a new tool window in PhpStorm in which we can expand remote directories and so on:

In the screenshot above, some files are displayed with a green background. These files are the files that are in our local project. This coloring is based on the mappings created earlier.
We can navigate between corresponding local and remote directories using Alt+F1.

3. Deploying files to the server

Deploying files to the server can be done in several ways. The easiest is to select the project, a folder or a single file in the Project tool window. The context menu contains Deployment | Upload to <server name> (or Deployment | Upload to... if no default server was set), which does just that: uploads the selection to the remote server.

We can see the progress from the File Transfer tool window which will open.

Downloading files works in a similar way. We can use the context menu in the Remote Host tool window and use the download option.

4. (optional) Drag-and-drop between project and server

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.

Drag-and-drop can be used to explore folders on the server that are not mapped as well.

More advanced synchronization and deployment of files and folders is described in Sync changes and automatic upload to a deployment server in PhpStorm.

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