Zend Framework – Up and Running

Zend Framework 2 (ZF2) is new in the technology ecosystem, and I find that the best way to learn a new technology is to set it up and start playing around with it. This space will show all the required installations and configurations to get things started in no time.

First, download and install the Zend Server. Once the installation is done, open the terminal and get into the Zend server Folder and clone the Zend Skeleton application (ZSA) from Github, which is a sample application. All the download links are in the Downloads section below.

$ cd /usr/local/zend/apache/htdocs/
$ git clone https://github.com/zendframework/ZendSkeletonApplication.git

If the statements above are executed correctly on the terminal, half the process is done. ZSA is already in the working directory of the server. The application won’t run just yet – there are some dependencies to be taken care of first. These dependencies are related to the libraries in the framework that the application will need to access. These libraries can be dependent on other libraries as well. This is where the Composer comes into picture, which is a dependency management tool. The composer picks up the required versions of the necessary packages and installs them into the project.

$ cd ZendSkeletonApplication
$ php composer.phar self-update
$ php composer.phar install

This completes the process of installing the dependencies and the application is now good to go.  Opening the browser and entering the following localhost address will bring up the ZSA application.

localhost:10088/ZendSkeletonApplication/public

This ensures that the ZF2 and the Zend Skeleton Application are running just fine on the local machine. Now lets try plugging in or installing a module to the Zend Skeleton Application. This is a fairly simple process if the Composer is used. Go ahead and open the composer.json file and add the code below and type the command in the Terminal. This is the package information that is fed to the composer to install the “Phly Contact” module to ZSA.

"require": { 
            "php": ">=5.3.3",  "zendframework/zendframework": "dev-master",                
            "phly/phly-contact": "dev-master"  
           }

$ php composer.phar install

At this point, we need to inform the application that a new module has been installed. Adding the module name in the application.config.php file in the ZSA folder does this.

‘modules’ =>
        array(
             ‘Application’,
             ‘PhlyContact’,
             );

Here is the URL to browse the contact form:

Localhost:10088/ZendSkeletonApplication/public/contact

There is an alternative way to install the module to the application by cloning the module in the vendor directory of the project and doing the exact steps as shown above. This method will just skip the usage of Composer as everything is done manually.  Now for the functionality aspect of the contact module, some configuration is needed to get this module working. The mail address has to be defined so that when the contact form is submitted, the mail comes to you. Replace the commented section in the module.config.php file with the mail details as shown below.

'Message’ => array (
           'To’ => array (
            ‘Your email-id’ => 'Your Name’,
           ),
       ),

So with this configuration set, when the contact form is filled and submitted, you will get an email with the details entered in the contact form.

In conclusion, the setup might look a bit hard, but once that’s done the framework seems pretty easy to play around with.

Setup

  • Mac OS X
  • Zend Framework 2
  • Zend Server

Download Links

3 thoughts on “Zend Framework – Up and Running”

  1. Hi,

    Very interesting, and I did everything as you say until “localhost:10088/ZendSkeletonApplication/public” but it doesn’t work!

    Haven’t you forgot to configure virtualhost or alias ?

    Regards

  2. To make it simple i have not included the code or steps to add a virtualhost. It wont hurt the application in anyway. Please make sure your port is 10088. It might be something else, but by default it sets it up for this port. What exactly is the error that you are facing ? Let me know so that i can help you out.

    Thanks,
    Vinay

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top