Building A Zend Framework 2 Application - Installing Zend Framework

Building A Zend Framework 2 Application - Installing Zend Framework

The first part of this tutorial is to install the Zend Framework library. For this tutorial I will be using PHP 5.5, but you could use PHP 5.4 but you should not be using anything less as version 5.3 has entered it's end of life now. I am also using an Ubuntu Server 14.04 on a virtual machine (VM), the install is a minimum install with only a SSH server installed so I can reach it via putty, or a terminal window. My method of teaching will be using a non automated way, I believe this will help you have a greater understanding of Zend Framework and installing software in a server environment.

I recommend having a Ubuntu server in a virtual machine so we can simulate how the code will run on a server, but it's not necessary. I will be adding a tutorial on how to do this later.

If you haven't already then you should install PHP on your computer, you can find the instructions for this at the PHP website. If you are on a Linux computer then you can get PHP installed via your package manager, if you are running a Debian version like Ubuntu, Raspberry Pi or Debian itself then you can install using the terminal window (make sure you have the right permissions to install packages) like:

sudo apt-get install php5-cli

For now we will only install the command line interface, we will install a full web server later when we finish the "Hello World" tutorial. If you are running running the lastest OSX then PHP is already installed, if you are running Windows then I would suggest you install Linux in a virtual machine like virtualbox as PHP under Window can be a little quirky I have found and it is better on an Linux box as it was written that environment. If you would like me to write a tutorial on setting up a virtual machine let me know in the comments.

Once you have PHP installed then you can test it with the command, php -v this should return something like:

PHP 5.5.9-1ubuntu4 (cli) (built: Apr  9 2014 17:11:57) 
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
    with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies

So as you can see I have my php installed and now. On a clean Ubuntu install once you have connected to you VM you should be in your home directory for me that's /home/shaun.

First make a folder called 'public', this is where all you code for your projects will live:

mkdir public

Then create a new folder inside this one called 'zf2-tutorial' this is where all our tutorial code will live.

mkdir public/zf2-tutorial

now we are going to move into this directory with:

cd public/zf2-tutorial

We are going to install composer which will handle all our dependencies like Zend Framework, using composer will greatly help us install and keep updated all our libraries we will use for more info go to Before we install composer we will need curl so:

sudo apt-get install curl

Now we can install composer, this will install it in this directory.

curl -sS | php

When you invoke this command you will see something like this output:

All settings correct for using Composer

Composer successfully installed to: /home/shaun/public/zf2-tutorial/composer.phar
Use it: php composer.phar

We can have composer installed globally on Linux and Mac by:

sudo mv composer.phar /usr/local/bin/composer

Now we can invoke composer with the command composer, for more details see I will take it we have install composer globally if you haven't then just swap the command composer with php composer.phar.

First we have to write a config file for composer to parse, this will include all our dependencies, which is just Zend Framework for now, so in our zf2-tutorial directory make a new file called 'composer.json', the config file uses the json format. the command line text editor I like is called nano which is easier than vi, so lets install nano first.

sudo apt-get install nano

Once installed type:

nano composer.json

This will open a editing screen then type:

  "name" : "ZF2 Tutorial",
  "require" : {
    "zendframework/zendframework" : "2.3.*"
  "repositories" : [ {
    "type" : "composer",
    "url" : ""
  } ]

This tells composer we will require the Zend Framwork version 2.3 and to install all minor updates and where to get it which is where most packages will reside. Now press Ctrl o to save the file and Ctrl x to exit back to the command line. Now we can install Zend Framework with:

composer install

Which should give you an output like:

Loading composer repositories with package information
Installing dependencies (including require-dev)
  - Installing zendframework/zendxml (1.0.0)
    Loading from cache

  - Installing zendframework/zendframework (2.3.1)
    Loading from cache

zendframework/zendframework suggests installing ext-intl (ext/intl for i18n features (included in default builds of PHP))
zendframework/zendframework suggests installing doctrine/annotations (Doctrine Annotations >=1.0 for annotation features)
zendframework/zendframework suggests installing ircmaxell/random-lib (Fallback random byte generator for ZendMathRand if OpenSSL/Mcrypt extensions are unavailable)
zendframework/zendframework suggests installing ocramius/proxy-manager (ProxyManager 0.5.* to handle lazy initialization of services)
zendframework/zendframework suggests installing zendframework/zendpdf (ZendPdf for creating PDF representations of barcodes)
zendframework/zendframework suggests installing zendframework/zendservice-recaptcha (ZendServiceReCaptcha for rendering ReCaptchas in ZendCaptcha and/or ZendForm)
Writing lock file
Generating autoload files

Congratulations you have installed Zend Framework! It will be in a new folder called vendor this is where composer installs all dependent libraries.

Every now and then we will want to update Zend Framework which can be done via composer update.

Next article in this series will focus on the Zend Framework 'Hello World' app.


21/04/2014 20:28:00 Shaun Freeman Filed Under: ZF2 Tutorial Composer, PHP, Zend Framework, zf2

Twitter Feed
Shaun Freeman @Zendmaster

Shaun Freeman @Zendmaster

I liked a @YouTube video 8 super heroic Linux commands that you probably aren't using

Shaun Freeman @Zendmaster

I liked a @YouTube video How to Maximize Your Productivity (As a Software Developer or Learning Programming)

Shaun Freeman @Zendmaster

I liked a @YouTube video From Carnivore Diet to Near-Death: Lessons Learned From Today's Most Popular Fad Diet

Shaun Freeman @Zendmaster

I liked a @YouTube video Carnivore Diet – Myths about Meat – Phil Escott – WHIS 2018

Shaun Freeman @Zendmaster