- 1. Prerequisites
- 2. Debugging with Z-Ray & PhpStorm
- 3. Profiling with Z-Ray and PhpStorm
- 4. Debugging and profiling with Zend Server and PhpStorm from Events List / Single Event
- 5. Deployment to Zend Server with .zpk package
- 6. Working with databases on Zend Server with PhpStorm
- 7. Additional configuration (optional)
There are two major ways to install Zend Server: either locally/standalone (downloading from Zend’s web site), or running a special Amazon Web Services instance. Both of them include a 30-day trial, so we’ll explore both options.
Please refer to Zend Server Documentation for more information on Zend Server configuration and usage.
1.1. Installation of Zend Server locally (or standalone on remote server)
First, download Zend Server for your operating system from Zend website. There are a few versions differing by the PHP interpreter version. To download Zend Server you will need to (quickly) register for a Zend Account.
Follow the steps of the installation wizard and finish the installation.
1.2. Using Zend Server at Amazon Web Services (AWS)
Different editions of Zend Server are also available in the AWS marketplace. With Zend Server running at Amazon Web Services, you have the perfect way to run high-performance, elastic, and dependable PHP-based Web & Mobile apps in the cloud.
Familiarize yourself with prices for the edition you prefer (PHP 5.5 Zend Server Developer Edition in our case), and proceed to create an account. There is a 30-day trial for Zend Server software, but AWS charges for the instance do apply. If you've never used AWS before, you may qualify for a full year of EC2 usage at no charge through the AWS Free Tier program (new cloud users only).
You will be offered to select parameters of the instance, such as configuration of the VM, region, security settings, and generate a new key pair to access the instance. Please review all the settings and proceed with AWS instance configuration.
After the procedure is completed, go to the AWS console to manage the newly created instance with Zend Server installed.
Watch the full video on Getting Started with Zend Server on AWS:
1.3. Launching Zend Server
As soon as your Zend Server is installed and running, open it following the link http://localhost:10081/ZendServer or https://localhost:10082/ZendServer (replace localhost with the hostname you’re using. In case of our AWS instance, the address is something like http://ec2-54-195-230-127.eu-west-1.compute.amazonaws.com:10081/).
On the next step, you will be offered to read and accept the License Agreement, and configure some initial parameters such as:
- Profile (Development / Production - Single Server / Production - Create or Join a Cluster) - Development profile suits most development environments
- Cluster Configurations (in case you selected Cluster on the previous step)
- Standard library packages to deploy
After the configuration is completed and you have successfully logged in, the Guide Page of Zend Server is displayed:
For educational purposes, we’ll just install a demo application from the Zend Server’s Guide Page. Please proceed to the Deployment section to learn how to prepare and deploy your applications to Zend Server. Demo application is a Zend Framework 2 skeleton application which includes customized monitoring and caching rules, events, recurring jobs and statistical data.
We’ll be using a local version of Zend Server below, but all the actions and workflows apply to remote AWS or standalone installation as well (additional configuration notes are provided where applicable).
1.4. Deploying Demo application
Click the Deploy Now button on the Zend Server Guide Page, then follow with deployment steps.
Enter the application name, path and virtual host.
Check that the application prerequisites are validated.
View the deployment summary, and proceed with deployment.
After the deployment process you will see brought to Zend Server’s applications list:
Here you can easily check information about the deployed application, check the status, proceed to monitoring, and perform many other actions.
We recommend that you familiarize yourself a bit with Zend Server before proceeding to the next step. Zend Server Getting Started Guide would be a good start for that.
2. Debugging with Z-Ray & PhpStorm
2.0. 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). To do so, just 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
(this one is the default command for AWS-run instances, Linux / Mac OS).
Windows users will need to:
- Download PuTTY ZIP http://tartarus.org/~simon/putty-snapshots/x86/putty.zip
- Convert the PEM file to a PPK file running puttygen.exe, loading the PEM file and then saving the private key to PuTTY's key format
- Run putty -R 10137:localhost:10137 remote-host.compute.amazonaws.com -i ZS.ppk -l ubuntu to setup the tunnel
- 10137 is the debugging port (can be changed in PhpStorm and Zend Server, see Additional Configuration section)
- remote-host.compute.amazonaws.com is the remote hostname where your Zend Server is installed
- ZS.pem is an authorization key (certificate generated by AWS or other authority, see this article for details)
- ubuntu is a username on remote host
Depending on your local privileges, you may need to execute the terminal command from super users (with sudo):
The SSH tunnel should be established every time before you initiate a debugging/profiling session. It’s NOT needed in the following situations:
- If Zend Server and PhpStorm are running on the same machine, or
- If there is a direct link between Zend Server & PhpStorm and no firewall is configured.
2.1. Toggle the button Start Listening for PHP Debug Connections.
2.2. Set a breakpoint in the source code (clicking on the left gutter near the line you would like to break at).
Alternatively, you can use the option Run | Break at first line in PHP scripts to have an automatic breakpoint at the first line of every PHP script you debug.
2.3. Open your application running on the Zend Server with Z-Ray bar enabled, and click Debug Icon | Debug Current Page.
2.4. Accept the incoming connection from Zend Debugger in PhpStorm.
2.5. PhpStorm will break at the breakpoint (or first line if that option is enabled), providing you excellent workflow of debugging your application in the IDE.
3. Profiling with Z-Ray and PhpStorm
All the notes and additional configuration for remote debugging from Step 2 apply to this step as well.
3.1. Toggle the button Start Listening for PHP Debug Connections.
3.2. Open your application running on the Zend Server with Z-Ray bar enabled, and click Debug Icon | Profile Current Page.
3.3. An application profile snapshot will instantly display 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 Additional Configuration section).
You may need to set up mappings for your project in Settings / Preferences | 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.
4. 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 monitoring events list available at Zend Server | Overview | Events.
A debugging / profiling session can be initiated from the list of events with relevant actions (Debug in IDE, Profile in IDE, Show in IDE). Before initiating a debugging / profiling session from the Zend Server side, make sure that the IDE is listening for debug connections (see Steps 2 & 3 for more information).
Similar actions can be invoked from the detailed description of any event as well:
5. Deployment to Zend Server with .zpk package
There is no GUI for Zend Server deployment in PhpStorm, but the IDE provides the ability to prepare ZPK deployment packages. This can be done either with a terminal or via Command Line Tools integration. We’ll focus on the second option, as it has the added convenience of providing completion options for command line tool commands and parameters.
After preparing the .zpk package, we’ll deploy it to the Zend Server.
5.1. Creating Command Line Tool for Zend Server deployment tool
(see the full tutorial on command line tools in PhpStorm)
A new command line tool can be created in Settings / Preferences | Command Line Tool Support clicking the Add button:
Choose Custom tool and set visibility (project or global):
Set the path to the tool (/usr/local/zend/bin/zdpack in our case; for different OS paths refer to Zend Server documentation) and alias:
Apply changes and open definition in the editor:
XML definition will be opened in the editor. Find the link to Zend Server's deployment tool (zdpack) repository in custom command line definitions directory and copy the entire XML from the repository to the opened editor tab:
Verify that the tool path and alias are valid in Settings / Preferences | Command Line Tool Support, by clicking the Edit tool button:
Now the zdpack command line tool can be brought up in Tools | Run Command... menu or with Ctrl+Shift+X (Cmd-Shift-X on Mac OS).
5.2. Preparing 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. Go to the directory to check that the resources have been created:
- 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 XML file (deployment.xml) as needed. The XML template is made 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
To prepare our test application for deployment, we needed the following commands:
- zdpack create drupal8a
- zdpack validate drupal8a/deployment.xml
- zdpack pack drupal8a
drupal8a.zpk has been generated in the root folder of our project.
5.3. Deploying package to Zend Server
In order to deploy a package you obtained on the previous step, open Zend Server | Applications and click the Deploy Application button:
Choose the .zpk package from the file system to proceed, and follow the deployment steps. Accept the license agreement, validate prerequisites and provide the required parameters.
Every application also has an update button next to it, if you wish to deploy a new version:
6. Working with databases on Zend Server with PhpStorm
Zend Server smoothly 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.
7. Additional configuration (optional)
7.1. Zend Server IDE integration configuration
You can always configure Zend Server IDE integration parameters in Zend Server | Configurations | IDE Integration, though this is usually not needed.
The debug port can be also changed here by switching Automatically detect IDE settings to Off:
Note that IDE Debug Port should be the set to the value as in the IDE (IDE configuration is shown in the next step).
Z-Ray configuration can be performed in Zend Server | Configurations | Z-Ray.
7.2. PhpStorm debug configuration
If needed, the Debug port and the Settings broadcasting port can be changed in PhpStorm | Settings / Preferences | PHP | Debug, but the defaults are good in most cases.
If you experience problems with Z-Ray system requests invoking the debugger multiple times in the IDE, make sure that the option Settings / Preferences | PHP | Debug | Ignore Z-Ray system requests is enabled.
7.3. 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.
To change that, have a look at Settings / Preferences | PHP | Servers.
This server can be used later to configure Run Configuration (by selecting Run | Edit configurations… or the corresponding action from the toolbar).
7.4. PHP interpreter configuration in PhpStorm
Zend Server’s local or remote interpreter can be used as a PHP interpreter in PhpStorm, and it can be added in Settings / Preferences | PHP | Interpreter | … Add Interpreter:
Learn more about setting Zend Server’s interpreter as remote PHP interpreter in PhpStorm from our blog post.
7.5. Using various tools running in Zend Server environment (PHPUnit, Behat, phpcs/phpmd)
Using a PHP interpreter bundled with Zend Server (local php interpreter or remote interpreter) gives an opportunity to get advantages of a PHP interpreter installed in a production-like environment. That way we can make sure there will be no inconsistencies when the application is finally deployed to production.
PHP interpreter is used for many workflows, such as: