Thursday, June 26, 2014

Creating an Application Package(.ZPK) for Deployment on Zend Server

Hi,

This article is aimed to help you better understand how to better deal with deployments in your development workflow and provide some best practices for deployments. Sometimes a bad production deployment can ruin all the effort you invested in a development process. Having a solid deployment workflow can become one of the greatest advantages of your team.

So what actually is deployment means ?

Deploying an application is the process of copying, configuring and enabling a specific application to a specific base URL on Zend Server or on a cluster. Once the deployment process has finished, the application becomes publicly accessible on the base URL. The server carries out this two step process by first staging the application, and then activating it after successful staging.



The deployment mechanism in Zend Server uses a ZPK file, which contains the source code, assets and the deployment descriptor.

Application Package(.zpk) file for the deployment on Zend Server can be created via a Zend-Studio GUI OR Linux console.Both are ease to implement.

Via Zend-Studio IDE: This is for GUI lover :)

Step 1: 
From Zend IDE, select your application for which you want to create the zpk file.

Step 2: 
Right click on the application, then selecting “Add Application Deployment Support”

 
It will create deployment.xml file in your aplication and opens it on your IDE.

Step 3: 
Screen that you will get on your IDE is:



Most of the fields are self explanatory but a few might require a few words.
  • Document Root – This is the document root which is relative to the base directory of the deployment. 
  • License – This is the relative path to a text file in the project directory structure that contains the EULA for the project.  During the deployment work-flow in the UI the end user will be presented with this if the file is available and will be required to agree to it before proceeding.
  • Persistent Resources – These are items that you don’t want to have overwritten during an upgrade.  For example, cache directories.

Dependencies

There are several different types of dependencies you can specify for your application.
These dependencies will be checked prior to deploying the application.  If they are not satisfied then the application will not deploy.

Triggers

There are several triggers that can be hooked into during the deployment process, each of which has a Pre and Post stage
  • Activate
  • Deactivate
  • Stage
  • Unstage
To set up a trigger simply double click on the stage that you would like to edit and a new file will be created for you.  In that file will be documentation on information on how to retrieve variables and parameters for your deployment scripts.
Speaking of variables and parameters, what is the difference?  There are two differences.
  1. Variables you cannot change during the deployment process.  What the value is in the deployment file is the value that you will get in the deployment script.  Parameters need to be specified during the deployment work-flow and also have some validation that you can do on the entered values whereas with variables you do not.
  2. Both are accessible via getenv() during deployment but variables are retrieved with their names “as is” but parameters are upper cased and prepended with “ZS_”.  So if you have a parameter named “ugly_Duckling” it would be accessed via getenv(‘ZS_UGLY_DUCKLING’)

Package

There may be files in your application that you want to include or exclude.  You can specify those in the Package panel.
 
Exporting
The last step is to export your project.  Right click on the project and select Export and choose “Deployment Package”.  This will output the project into a ZPK file that you can then upload to your Zend Server instance or Zend Application Fabric installation where it will be deployed to your website. 







=================================================
 Via Linux Console : This is for Command line lovers :)
=================================================

Here, i am using Zend's Deployment Tool that allows you to create a skeleton package, and pack the contents into a .zpk package.

Tool location - The tool is located in:
  • Linux - '/usr/local/zend/bin/zdpack'
  • Windows - 'C:Program Files\Zend\ZendServer\bin\zdpack' -OR- as a 
  • standalone (if downloaded separately from the product).

Usage - Run the help command (Linux: '<install_dir>/bin/zdpack --help'; Windows: 'zdpack.exe --help') from the bin directory to see the usage.

The command line actions are:
Step 1: 
Select a directory and use the create command (Linux: '<install_dir>/bin/zdpack create <application-name>'; Windows: zdpack.exe create <application-name>'
where is your application's name) to create the skeleton of your .zpk package. This includes the XML descriptor file, the data folder and the hook scripts (templates).
Go to the directory to see the resources that 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. 
  • deployment.xml file - The template of the XML descriptor for you to edit as needed.

Step 2:
Perform the following actions:
  • Place your application files in the data folder. 
  • Edit the hook scripts according to your needs. 
  • Edit the XML file as needed. The XML template is made up of example elements.  
  • Validate the package by using the validate command (Linux: '<install_dir>/bin/zdpack validate [--schema=<xsd-file>] <package-xml-descriptor-file>'; Windows: 'zdpack.exe validate [--schema=<xsd-file>] <package-xml-descriptor-file>'). 

For example:
# /usr/local/zend/bin/zdpack validate --schema="/usr/local/zend/share/deployment.xsd" deployment.xml


NOTE: For ZF2 application zpk file creation, I edit the deployement.xml file for the document root settings i.e.
<docroot>data</docroot> 
TO 
<docroot>data/public</docroot>

Step 3:
Use the pack command (Linux: '<install_dir>/bin/zdpack pack <application-name>'; Windows: 'zdpack.exe pack <application-name>') to pack the contents into a .zpk package. By default, the Deployment Tool will create the package in the working directory.
For Example:
# /usr/local/zend/bin/zdpack pack my_application_dir


Once you have a .zpk application package ready and packed, you can deploy your application OR update an existing application.


--
Bye Buddy

Monday, June 23, 2014

OOP : When to prefer an Abstract Class and Interface

Hi,

Abstract classes allow you to provide default functionality for the subclasses.

Why is this extremely important though?
If you plan on updating this base class throughout the life of your program, it is best to allow that base class to be an abstract class.

Why?
Because you can make a change to it and all of the inheriting classes will now have this new functionality.

If the base class keep on changing and an interface was used instead of an abstract class, we are going to run into problems. Once an interface is changed, any class that implements that will be broken. Now if it's just you working on the project, that’s no big deal. However, once your interface is published to the client, that interface needs to be locked down. At that point, you will be breaking the clients code.

As per my personal experiences, frameworks is a good place to show when and where to use both an abstract class and an interface.

Another general rule is if you are creating something that provides common functionality to unrelated classes, use an interface. If you are creating something for objects that are closely related in a hierarchy, use an abstract class.

An Example of this would be something like a business rules engine. This engine would take in multiple BusinessRules as classes perhaps? Each one of these classes will have an analyze function on it.

public interface BusinessRule{
     Boolean analyze(Object o);
}

This can be used ANYWHERE. It can be used to verify the state of your application. Verify data is correct. Verify that the user is logged in. Each one of these classes just needs to implement the analyze function, which will be different for each rule.

Where as if we were creating a generic List object, the use of abstract classes would be better. Every single List object is going to display the data in a list in some form or another. The base functionality would be to have it go through its data provider and build that list. If we want to change that List object, we just extend it, override our build list function, change what we want and call super.buildList();

In Brief: interfaces means you are just defining a list of functions and that abstract classes has the option of providing default functionality.

Tuesday, May 27, 2014

WebSite Page Locking

Hi Everybody,

Today, Again i shared my next module "Page-Lock" in Zend-Framework 2.

Basically page locking is important when you want your site should be more secure in terms of transactions and updation happening across the site.


This module contain the following feature:
1. If one user open let's say the home page, then the same user can not open it on the other browser.

2. If your application handling the login mechanism then this module also handle the locking on logged-in user accordingly.

3. It has the feature where you can set the time period of locking. Its adjustable from flat file.

4. It's lightweight, simple and shower.


You can download the page-lock module from  the Zend-Framework 2 module sites i.e.

URL : https://github.com/tarun-singhal/page-lock

Here, you can find the installation process i.e. how to implement it in your application.


I will be more thankful to you, if i got some feedback from your side :)





Bye...


Thursday, May 22, 2014

Zend Framework 2: JobQueue Module

Hi,

Today i share my first module "JobQueue" on Zend-Framework 2 module site :)

URL : http://modules.zendframework.com/

JobQueue is a Feature of the Zend-Server and i use this feature in Zend-Framework2.

JobQueue Module is basically use to handle heavy background process. It helps to increase the Web App performance.  JobQueue service can be used for the following scenarios :
  1. Preparing data for the next request (pre-calculating)
  2. Pre-caching data
  3. Generating periodical reports 
  4. Sending e-mails 
  5. Cleaning temporary data or files 
  6. Communicating with external systems.

    Job Queue module is useful with Zend Server 5 (though not as part of the Community Edition).
You can download the JobQueue Module from Git-hub i.e
URL : https://github.com/tarun-singhal/JobQueue

NOTE: Please make sure your zend-server service should be running.

Below screen-shot that shows, once you run the module in your application then you can view your application job status send via JobQueue module on zend-server.
 


Wednesday, March 26, 2014

GIT Tag

Hi,

Create GIT Tag on your project is useful to keep track of your project release.

Step to create the Tag in GIT are:

1.  # git tag -a V2 -m "tag 2"

2. # git push origin V2

Where, V2 : relate the tag name

If you want to switch into previous tag

# git checkout tag-name

where tag-name, is the tag no where you want switch back/fro to the release.


To get list GIT tag
# git tag


To cloning the branch or tag
# git clone --branch tag_name repo_url

Where,
tag_name : GIT tag no.
repo_url : GIT URL


To get the checkout from the Tag
# git checkout tags/tag-name

I hope above GIT tag command is useful to manage tag.






Thursday, February 27, 2014

Linux : Replace string in multiple files recursively

Hi,

If you want to search and replace specific string from multiple file recursively then below command is useful  for it :

Linux Command:
# grep -rl "string1" * -R | xargs sed -i 's/string1/string2/g'


Here above command is combination of  'grep' and 'sed', 
grep : Command will search for "string1" and returns file-name where string1 found

sed : will replace the "string1" to "string2"

string1 : old string
string2 : New string

You can watch the above process on youtube also...

http://youtu.be/GcopukZz3io

Friday, February 21, 2014

Hide User Names on the Login Screen in Ubuntu

Hi,

This is for to clean the login screen i.e. multiple users listing should not show on login screen.

It can be accomplish with some changes in LightDM desktop manager configuration.

It brings the new layer of security that any intruder should use right user account to login into your machine.

Steps to make changes it in LightDM desktop manager.

Step 1: Open lightdm.conf file i.e.
# vi /etc/lightdm/lightdm.conf

Step 2: Add below 2 lines in the lightdm.conf file

greeter-hide-users=true
allow-guest=false

Step 3: Above line will hide the user listing on login screen.

I hope above steps will helpful to enable the clear Login screen.


 


Ubuntu 12.04 Grub to boot into single user mode

Hi,

Steps to boot in single user mode in Ubuntu 12.04:

Step 1: When you start your system, press "shift" key continuously to get the grub loader screen.

Step 2: In Grub 2 menu, select the menu with Linux 3.2.0.23-generic-pae highlighted.

Step3: Press 'e' to edit the grub2 menu.

Step 4:  Move the cursor to the line that starts with "linux /boot/vmlinuz-3.2.0-23-generice-pae".

Step 5: Change the content "ro quiet spalsh $vt_handoff" To "rw init=/bin/bash".

Step 6: Press "Ctrl+x" to continue boot to in single user mode.

Step 7: Now you will get prompt of the root user.

Step 8: Change root user password,
# passwd root

Step 9: Now sync and reboot the system i.e.
# sync
# reboot -f

I hope, above steps are helpful to change the root user password in single user mode.

Monday, December 9, 2013

Jquery : Useful Selectors

Hi,

Jquery Useful Selectors are: 

1. How to set checked attribute in CheckBox.

$("."+cssClass).attr('checked', True);


2. How to select element on the basis of disable attribute:

$("."+cssClass+":not[disabled]").attr('checked', true);







Note: Above selector solution will be increased ASAP.

ZF2 : Custom config file inside module(s)

Hi,

ZF2 has the feature to create custom config file inside module(s).

Its provide help to declared variable those will used inside the particular module.

It is independent of main ZF2 config file.

Below are step to create/Use the custom config file inside the module:

Step 1: Create Module as Report

Step 2: Create custom config file in module's config directory i.e. module.customconfig.php, 

Step 3: Sample content inside module.customconfig.php

return array(
         'report' => array(
              'header' => array(
                    'name' => 'Name'
               )
         ),
);


Step 4: In controller of Report Module, Ex: ReportController.php

In Action: 

$config = $this->getServiceLocator ()->get ( 'config' );
//Take custom-config data from config file
$data = $config['report'];
print_r($data);