PhpStorm 2024.2 Help

Zend server

Zend Server seamlessly integrates with PhpStorm, providing advanced features for debugging and profiling your web applications.

Zend Server is an integrated platform for mobile and web apps, helping in all phases of the application lifecycle. Zend Server includes Z-Ray, which gives unprecedented, in-context visibility inside apps, by showing in real time what exactly happens to construct each page. It helps developers write better code, detect and fix issues earlier, and collaborate with the operations staff to resolve production problems faster.

In this tutorial we’ll look into how to configure integration and proceed with debugging, profiling, or deploying your code, as well as using many built-in tools with PhpStorm, while Zend Server takes care of your PHP environment.

The following video will walk you through getting started with Zend Server:

For more information about Zend Server configuration and usage, refer to the Zend Server Documentation.

Debugging with Z-Ray & PhpStorm

Z-Ray is a browser tool window that displays all the under-the-hood details of a page request, across all the PHP scripts involved in building the page. Z-Ray is injected into the response coming from your PHP app and shown right in the browser you're using for development, so you get much greater insight without changing your development workflow.

Zray Overview

SSH tunnel configuration for remote debugging

If you are using AWS or any other standalone remote installation of Zend Server, some configuration is needed to prevent your firewall from blocking debugger communications.

To get a remote session running, set up an SSH tunnel for the debug port (10137 by default). If you are running Linux or macOS, run the following command from your local terminal where PhpStorm is running:

ssh -R 10137:localhost:10137 remote-host.compute.amazonaws.com -i ZS.pem -l ubuntu

If you are running Windows, do the following:

  • Download PuTTY

  • Convert the PEM file to a PPK file by running puttygen.exe, loading the PEM file, and saving the private key to the PuTTY's key format

  • Run the following command to set up the tunnel:

putty -R 10137:localhost:10137 remote-host.compute.amazonaws.com -i ZS.ppk -l ubuntu

where:

Parameter

Description

10137

The debugging port (can be changed in PhpStorm and Zend Server, see Additional Configuration section).

remote-host.compute.amazonaws.com

The remote hostname where your Zend Server is installed.

ZS.pem

An authorization key (certificate generated by AWS or other authority).

ubuntu

A username on the remote host.

Depending on your local privileges, you may need to execute the terminal command from a superuser (with sudo.

The SSH tunnel should be established every time before you initiate a debugging/profiling session. It is not needed in the following situations:

  • If Zend Server and PhpStorm are running on the same machine.

  • If there is a direct link between Zend Server & PhpStorm and no firewall is configured.

Debug your Zend application

  1. In PhpStorm, enable listening to incoming debug connections by doing any of the following:

    • Click the Start Listening for PHP Debug Connections button on the toolbar/the status bar.

    • Select Run | Start Listening for PHP Debug Connections in the main menu.

    This ensures that PhpStorm reacts when a debugging session is started on the web server and opens the Debug tool window automatically. Before starting a debugging session, make sure that either a breakpoint is set or the Break at first line in PHP scripts option is enabled on the Debug page of the Settings dialog Ctrl+Alt+S.

  2. Set a breakpoint in your code by clicking in the editor gutter near the line you would like to break at.

  3. Open your application running on the Zend Server with the Z-Ray bar enabled, click the Debug icon the Debug icon and select Debug Current Page.

    Debug Current Page
  4. Accept the incoming connection from Zend Debugger in PhpStorm.

    Accept incoming connection

    PhpStorm will break at the breakpoint (or first line if that option is enabled), providing you with the workflow for debugging your application in the IDE.

    Zend debugger breakpoint

Profiling with Z-Ray and PhpStorm

All the notes and additional configuration for remote debugging apply here as well.

Profile your Zend application

  1. In PhpStorm, enable listening to incoming debug connections by doing any of the following:

    • Click the Start Listening for PHP Debug Connections button on the toolbar/the status bar.

    • Select Run | Start Listening for PHP Debug Connections in the main menu.

    This ensures that PhpStorm reacts when a debugging session is started on the web server and opens the Debug tool window automatically. Before starting a debugging session, make sure that either a breakpoint is set or the Break at first line in PHP scripts option is enabled on the Debug page of the Settings dialog Ctrl+Alt+S.

  2. Open your application running on the Zend Server with the Z-Ray bar enabled, click the Debug icon the Debug icon and select Profile Current Page.

    Profile Current Page

    An application profile snapshot will open in PhpStorm.

Make sure to select the Server in order to take advantage of context menu actions, such as Jump To Source, Quick Definition, Quick Documentation (more information about server configuration is available in the Additional Configuration section). You may need to set up mappings for your project in Settings | PHP | Servers. You need to use path mappings when the paths to the files processed by the server differ from the paths to the files in the project. A path mapping specified for a parent directory is automatically applied to all its subdirectories. If necessary, you can specify path mappings for any subdirectory or even an individual file separately.

Debugging and profiling with Zend Server and PhpStorm from Events List / Single Event

Zend Server is tracking everything that’s going on with your application. To easily see all the issues, use the list of monitoring events available at Zend Server | Monitoring | Events.

A debugging / profiling session can be initiated from the list of events with relevant actions (Debug in IDE, Profile in IDE, or Show in IDE). Before initiating a debugging / profiling session from the Zend Server side, make sure that the IDE is listening for debug connections. For more information, refer to Debugging with Z-Ray and Profiling with Z-Ray.

Zend events list actions

Deployment to Zend Server with a ZPK package

There is no GUI for Zend Server deployment in PhpStorm, but it still lets you prepare ZPK deployment packages. This can be done either by using a terminal or via the Command Line Tools integration.

We’ll focus on the second option, as it conveniently provides completion options for command line tool commands and parameters.

After preparing the ZPK package, we’ll deploy it to the Zend Server.

Create a command line tool for Zend Server deployment tool

  1. In the Settings dialog (Ctrl+Alt+S) , go to Tools | Command Line Tool Support.

  2. Click the Add button, select Custom tool from the list, and set the tool visibility (project or global).

    Creating a custom Zend tool
  3. Set the path to the tool (/usr/local/zend/bin/zdpack in our case; for OS-specific paths, refer to the Zend Server documentation) and alias.

    Custom Zend tool settings
  4. Apply changes and click the Edit Source button to open the tool definition in the editor.

  5. Find the link to Zend Server's deployment tool (zdpack) repository in the custom command line definitions directory and copy the entire XML from the repository to the opened editor tab.

    Custom Zend tool definition

You can now launch the zdpack command line tool by either selecting Tools | Run Command... in the main menu or pressing Ctrl+Shift+X.

Prepare a deployment package in PhpStorm

  1. Select a directory and use the create command to prepare the skeleton of your ZPK package. This includes the XML descriptor file, the data folder and the hook scripts:

    zdpack create application-name
  2. Verify that the resources have been created in the specified directory:

    • Data folder - The folder that will contain your application files.

    • Scripts folder - The hook script skeletons available for you to edit as needed, and existing monitoring and caching rules.

    • deployment.xml file - The template of the XML descriptor for you to edit as needed.

  3. Perform the following actions:

    • Place your application files in the data folder. Edit the hook scripts according to your needs.

    • Edit the deployment.xml as needed. The XML template is comprised up of example elements. The required elements are name, version, and appdir.

    • Validate the package by using the validate command

    zdpack validate package-xml-descriptor-file
  4. Use the pack command to pack the contents into a ZPK package. By default, the Deployment Tool will create the package in the working directory.

    zdpack pack application-name

    In our case, to prepare the test application for deployment, we need to run the following commands:

    zdpack create drupal8a zdpack validate drupal8a/deployment.xml zdpack pack drupal8a

    As a result, drupal8a.zpk has been generated in the root folder of our project.

Deploy a package to Zend Server

  1. Open Zend Server | Applications | Manage Applications and click Deploy Application.

  2. Choose the ZPK package from the file system and follow the deployment steps. Accept the license agreement, validate prerequisites, and provide the required parameters.

Working with databases on Zend Server with PhpStorm

Zend Server integrates with various databases (MySQL by default), which can be very handy for development purposes. PhpStorm comes with Database & SQL support. Make sure to connect the IDE to the development instance of Zend Server to take advantage of these tools.

Additional configuration (optional)

Configuring integration with Zend Server

You can configure the Zend Server IDE integration parameters under Zend Server | Debugger, though this is usually optional. For example, the debug port can be changed here by triggering the Autodetect IDE settings option:

Additional IDE settings

Note that debug port must be the set to the same value as in PhpStorm. If needed, the Debug port and the Settings broadcasting port can be changed in PhpStorm on the PHP | Debug page of the Settings /Preferences dialog Ctrl+Alt+S.

PhpStorm debugger settings

If you experience problems with the Z-Ray system requests invoking the debugger multiple times in PhpStorm, make sure that the Ignore Z-Ray system requests checkbox is selected on the PHP | Debug page of the Settings dialog Ctrl+Alt+S.

Setting Zend Server as a Server in PhpStorm

As soon as a debugging or profiling session is established between Zend Server and PhpStorm, Zend Server will be added as a PHP server in PhpStorm configuration. If necessary, you can modify its settings PHP | Servers page of the Settings dialog Ctrl+Alt+S.

Servers settings

This server can be used at al later point to configure Run Configurations.

Configuring PHP interpreter in PhpStorm

Using a PHP interpreter bundled with Zend Server provides the advantages of a PHP interpreter installed in a production-like environment. This way, we can make sure there will be no inconsistencies when the application is deployed to production.

You can use a PHP interpreter, for example, to test with PHPUnit or Behat, or analyze your code by using PHP code quality tools.

The interpreter can be set up on the PHP page of the Settings dialog (Ctrl+Alt+S) . For more information, refer to Configure local PHP interpreters.

Using the ZF Tool command line tool from PhpStorm

Configure zftool as a command line tool

  1. In the Settings dialog (Ctrl+Alt+S) , go to Tools | PHP Command Line Tool Support.

  2. Click the Add button on the toolbar.

  3. In the Command Line Tools dialog, choose Zend Framework 1 Tool or Zend Framework 2 Tool from the list, and specify its visibility level (Project or Global).

    the Command Line Tools dialog
  4. When you click OK, the Zend Framework Tool dialog opens.

    Provide the path to ZF Tool depending on the Zend Framework version used and choose one of the configured PHP interpreters from the PHP Interpreter list. For more information, refer to Configure local PHP interpreters and Configure remote PHP interpreters.

    • <Zend-Framework-home>/zf for Zend Framework 1.

    • <Zend-Framework-home>/zf.php or <Zend-Framework-home>/zftool.phar for Zend Framework 2.

  5. Click OK to apply changes and return to the PHP Command Line Tool Support page. Optionally, click the Edit button to edit the tool properties, or the Edit Source button to customize the commands set. For more information, refer to Customize a tool.

Run zftool commands

  • Go to Tools | Run Command or press Ctrl twice.

    In the Run Anything window that opens, type the call of the command in the <zf> <command> or <zf2> <command> format.

    The command execution result is displayed in the Run tool window.

    Running a zftool command

Terminate a command

Last modified: 30 July 2024