A Guided Tour of Zend Application Deployment Support

This tutorial will help you understand how to deploy your application using the deployment.XML file.

You will be working with an existing GitHub project and its deployment.xml file to customize your application’s deployment and to create a ZPK package.

In  this Tutorial You will Learn

Provided Items

For this tutorial we will provide you with the following:

Prerequisites

Step 1: Creating a GitHub Project in Zend Studio

For this tutorial you will first need to create a GitHub project in Zend Studio. You will be importing an existing GitHub project that we have provided for the purposes of this tutorial.

For information on creating a GitHub account and project, see http://help.github.com

 

 

Instructions on how to complete a procedure

To create a new project from GitHub in Zend Studio:

  1. Go to File | New | PHP Project from GitHub.
    The GitHub Repository dialog appears.
    If the GitHub plugin is not installed, Zend Studio will automatically begin the process for installing the plugin that will include restarting the program. Wait until this installation is complete before continuing. For more information see Customizing and Registering Zend Studio.

3_new_github_project.JPG

  1. Enter the following information:

  • Project Name: Name your project deployment_tutorial

  • User: zend-studio

  1. Click Refresh.
    Your application location will appear in the Location URL field.

  2. Click Next to move to the Launch Settings dialog.

  1. Select Launch URL,  enter the address of the local host server and click Finish.

  2. Run your application by right-clicking the project in the PHP Explorer and selecting Run As PHP Application.
    Your application opens in the Zend Studio workspace and is running locally.

4_project_running_locally.JPG

Note:

It is recommended that you save a copy of your project on your machine before continuing this procedure.

 

 

Step 2: Enabling Deployment for your Project

The project we have created was not defined to include Application Deployment Support. In order to work with the deployment.xml file and create the ZPK application package, Application Deployment Support must be enabled.

 

 

Instructions on how to complete a procedure

To enable deployment:

Add deployment support to your project by right-clicking your project in the PHP Explorer view and select Configure | Add Application Deployment Support.
Your project will appear in the PHP Explorer view with a deployment.xml file.

5_add_deployment_support.JPG

 

 

Step 3: Working with the deployment.xml File

You will now learn how to edit the deployment.xml file before creating the ZPK package. The deployment.xml file allows you to customize the deployment settings for your application.

After enabling Application Deployment Support, the deployment.xml file appears. The following procedure is according to the tabs in the file.

 

 

Instructions on how to complete a procedure

Overview Tab

In the Overview tab, enter general information about the project:

  • Name: deployment_tutorial

  • Version: 1.0

  • Application Directory: data

Dependencies Tab

Before deployment, Zend Server checks that the target's settings match the application defined dependencies.

  1. Click Add.
    The Add Dependency dialog is displayed.

Add_Dependency.png

 

  1. Click PHP Version.
    The Version Dependency dialog appears.

php_version_dependency.jpg

 

  1. Select Matches and enter “5.3.0” in the Minimum field.

  2. Click Finish.
    The dependency is displayed in the Dependencies list.

Depencies_List.png

 

Triggers Tab

The Triggers tab includes the Deployment Scripts area and the Variables and Parameters area.

triggers_view.jpg
 

Deployment Scripts

You will now create new files that include the deployment scripts for this tutorial project.

  1. Double-click the postStage and postActivate triggers.

  2. When prompted, click Yes to confirm the creation of the trigger scripts.
    The new PHP trigger files are displayed and also appear in the Scripts file in the PHP Explorer view.

  3. Copy and paste code into the newly created trigger files:

Parameter Script

This file is used for converting user-entered parameters and built-in environment parameters to local php parameters that can be used by all the script files.

  1. In PHP Explorer, expand the project, right-click the Scripts file, and select New | PHP File.
    The New PHP File dialog is displayed.

6_add_post_scripts_and_param_file.JPG

  1. In the File Name field, enter “deployment_params.inc”, and click Finish.
    The new  file is displayed and appears in the Scripts file in the PHP Explorer.

  2. Copy the code for the relevant file from Tutorial Example Codes and paste into the new file.

  3. Save the file.

Additional Scripts
  1. Create two more PHP files named as follows:

  • deployment_demo_table.sql- This file is the SQL database dump file.

Note:

The "TABLE_PLACEHOLDER" string will be used in the subsequent create_table.php file.

  • create_table.php- This file creates the table using the SQL file.

  1. Repeat steps 3-4 in the previous section for each file.
    Your project now includes five script files that are displayed in the deployment.xml main view and in the PHP Explorer.

8_copy_paste_code.JPG
 

Variables and Parameters

Add parameters that are used in the hook scripts. You will enter the value of the parameters during the deployment process.

  1. Return to the Triggers tab.

  2. Click Add Parameter.
    The new parameter will appear in the Variables and Parameters list.

  3. In the Parameter Details area, which can be opened by selecting a parameter, enter the following definitions:

  • ID:DB_Host

  • Type:  string

  • Mark This Parameter is Required.

  • Display Text: db host.

  • Default Value: localhost.

parameter_define.jpg

  1. Repeat steps 2-3 with the following definitions:

Parameter ID

Type

This Parameter is required

Display Text

Default Value

DB_Name

string

Y

db name

test

DB_Table

string

N

table name

employee

DB_USERNAME

string

Y

username

 

DB_PASSWORD

password

Y

db password

 

 

  1. The new parameters are displayed in the Variables and Parameters list:

Adding_Parameters.png

Package Tab

In the Scripts Directory Content, we define which files to include in the package.

  1. Click the Package tab in the deployment.xml file.

  2. In the Scripts Directory Content, mark the all the scripts in the scripts file.

8_Package_Tab.JPG

  1. Save the project.

 

Step 4: Launching the Application

You will now test the application by launching it on your development server.

 

 

Instructions on how to complete a procedure

To launch the application:

  1. Click the Overview tab in the deployment.xml file.

  2. In the Testing Area, click Launch a PHP Application.
    The Launch PHP Application dialog is displayed, warning that no target has yet been defined for the deployment.

9_launch_deployment.JPG

  1. Select Add New Target.
    The Add Target dialog is displayed.

10_add_target.JPG

  1. Select the Detect Local icon and click Test Connection.

  2. If no problems arise, click Finish.
    The Launch PHP Application dialog is displayed again. Change the URL to tutorial_deploy to avoid two applications with the same name.

13_tutorial_deploy.JPG

  1. Click Finish.
    The Parameters dialog is displayed.

14_add_local_params.JPG

  1. Enter the values for the parameters as you defined them.
    The application will open in the internal browser.

15_deployed_in_browser.JPG

 

 

Step 5: Exporting the Application

You will now package the application into a ZPK file. This makes your application portable and accessible by creating a file that can easily be sent to other members of the work process.

 

 

Instructions on how to complete a procedure

To package your application:

  1. Click the Overview tab in the deployment.xml file.

  2. In the Exporting area, click Export Wizard.
    The Export Deployment Package dialog is displayed.

Export_Dialog.png

  1. Select the project to be packaged.

  2. Select the export destination by clicking Browse.

  3. Click Finish.
    Zend Studio creates the ZPK package and exports it to the designated destination folder.  

 

 

 

 

Related Links

Related Links:

Zend Studio 9 Tutorials

Deploying Applications to Zend Server