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:

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:

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:

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

now we are going to move into this directory with:

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 https://getcomposer.org/. Before we install composer we will need curl so:

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

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

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

Now we can invoke composer with the command composer, for more details see https://getcomposer.org/doc/00-intro.md. 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.

Once installed type:

This will open a editing screen then type:

This tells composer we will require the Zend Framwork version 2.3 and to install all minor updates and where to get it https://packagist.org/ 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:

Which should give you an output like:

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.

Enjoy!

  • Henry

    Hi Shaun,
    I am new to Zend Framework and Ubuntu.
    When I found and read this article I’m so excited and I want to learn more from you. Please continue on writing ZF2 tutorial. 🙂

    • Thanks Henry,
      I certainly will, I have been quite busy just recently with a ZF2 project I am working on called Uthando-CMS.
      Is there any subject you would like me to cover first? Or would you like to see how we can get the simple application going first?

      And thanks for reading as I thought no one was…

      • Henry

        Hi Shaun,

        No need to thanks me Shaun. I’m the one who need to say thanks 🙂
        It’s been a while since I’m confused and struggling found a good tutorial. It’s just a matter of time the others will find and read your writing Shaun.

        And good luck with your project Shaun. 🙂

  • Henry

    I would like to see how we can get the simple application going first Shaun. Because I think it’s better for me to know the basic first. I want to be honest here. Even if I can build a ZF2 application using zf2 skeleton application, I still know nothing about ZF, that’s why I found your article is very interesting. I hope you can help many beginner in ZF like me Shaun. 🙂

    I hope you understand what I mean Shaun. Sorry for my bad english.

  • Dan Waber

    Thank you.. it is very helpful…

  • But sir how we open this in localhost?

    • Shaun Freeman

      Hi,

      Thanks for reading, if you read part 3 in this series you will get your answer.

  • Pramod Sah

    Hi Shaun,
    After searching too much on google I got this article. Really its very simple and easy to understand.

    Thanks,
    Pramod Sah

    • Shaun Freeman

      Thank you, I am glad it helped you. Happy coding!.