Chapter 4. Installing The Zend Framework

4.1. Introduction

The past few chapters were replete with theory so it will be a nice break to do something concrete. Afterall there's only so much I can pummel your brain with before I surrender and get on with the show! I know books with tons of theory can be tough going but stick with it - it's well worth letting it all kick around at the back of your mind.

When I started writing this chapter about installing the Zend Framework I complained on Twitter that the Zend Framework would be easier to install if someone created a PEAR package for it (something Symfony and ezComponents do). Going by the responses this is actually a plan Zend are considering and which will make some of the following chapter obsolete if it does.

4.2. Before You Install The Framework

Before installing the Zend Framework you're going to need a fully functional development system. While writing this book I used Ubuntu Linux 9.04 (the Jaunty Jackalope), Apache 2.2, MySQL 5.0.65 and PHP 5.2.6 - a typical up to date LAMP system from the Ubuntu repositories in other words. Any Windows equivelant using similar versions of Apache, MySQL and PHP would be equally usable. To follow this book, I'm making the assumption that you are at least using the Apache web server and MySQL database management system. If you want to use ISS and MSSQL, I'm not going to stop you or anything but be aware some steps in the next couple of chapters will need to be tweaked to apply to those systems. Where it's needed throughout the book, I will mention Windows specific instructions below the Linux ones.

Installing all these is not something I'm going to cover. The internet is practically swamped with installation guides for every conceivable system and scenario, and you should use your preferred search engine to search for relevant instructions. The PHP manual is a good place to start but you can also either use your Linux distro's update system (like aptitude for Ubuntu) or even grab an all-in-one development system for Windows like XAMPP to get this done in fewer steps.

4.3. Getting The Zend Framework

You can currently get the Zend Framework in a few ways. You need to be careful however since some methods tend to be a bit...dodgy.

4.3.1. Download As Compressed Archive File

The simplest is to grab the most recent version from http://framework.zend.com/download/latest. As I'm writing this, the latest version is 1.9.1. You will need to extract the downloaded archive to a working location like your OS desktop. We'll cover the structure of the downloaded files shortly.

Once you have the framework files downloaded it's worth taking some time to learn your way around them. You see the Zend Framework, as we discussed in the last chapter, has four different collections of useful classes: Standard, Standard Incubator, Extras, and Extras Incubator. The most important one is Standard - it's the main collection you will be used. This complicates things a little since the major part of any initial setup is knowing what to add to your PHP include_path, whether you intend editing it in a php.ini configuration file or changing it with set_include_path() when you are creating a new application. Here's where to find each of those four collections relative to the parent Zend Framework directory you extracted:

Standard: /library
Standard Incubator: /incubator/library
Extras: /extras/library
Extras Incubator: /extras/incubator/library

Inside each of those locations is a directory called either Zend or ZendX. The "X" postfix identifies extra components distributed for which Zend offers no official support (the lack of support doesn't prevent them being very useful however!). It is the above paths (the full path from your root or drive letter) you'll need to eventually add to the PHP include_path. For example if I copied the framework files to /usr/share/php/zf the full path to add to my include_path for the Extras Incubator would be /usr/share/php/zf/extras/incubator/library. This should be enough to go away and edit php.ini if you want to (not a bad idea) and I'll show you how to manage the PHP include_path for a Zend Framework application in subsequent chapters if you don't wish to perform any php.ini editing.

With the information above go copy the framework files somewhere more permanant. I use /usr/share/php/zf on Ubuntu but any location will work. Just try not to forget where you put it!

4.3.2. Checkout From Subversion

If you prefer keeping pace with active development in trunk, or keeping your fixes updated from the current release branch, you can also "checkout" the framework from it's subversion repository at http://framework.zend.com/svn/framework/. Subversion is a version control system which developers use to maintain a central online repository for source code they are developing. Its attraction is allowing multiple developers to work on the same source code without constantly swapping notes or taking turns.

I would suggest creating a permanent location like /usr/share/php/zf and checking out the repository into that directory. The only problem with subversion is that there is a lot (by a lot I mean a mind blowing crazy number) of files when you include all the branches and tags. To grab only the needed files from subversion you'll need to make four separate checkouts only updating from the locations of the main four file collections whose URLs are:

Standard: http://framework.zend.com/svn/framework/standard/trunk/library/
Standard Incubator: http://framework.zend.com/svn/framework/standard/incubator/library/
Extras: http://framework.zend.com/svn/framework/extras/trunk/library/
Extras Incubator: http://framework.zend.com/svn/framework/extras/incubator/library/

If using trunk for each is not your thing, you can instead use the relevant release branch for each.

Simplest way to do this is to create the parent directory as usual, for example at /usr/share/php/zf, and inside this run the svn checkout command referencing four other directories named for the collection name, similar to standard, standard_incubator, extras, extras_incubator.

Whenever you want to update to the latest development code, you only need to perform a subversion update for each of those four directories.

4.3.3. Download As A Linux Distribution Package

There is a third option - grab it from your Linux distribution's update server using apt-get or aptitude (if using a Debian based distribution). I really don't recommend this since you may end up with a framework version that was released months behind the latest one. This is borderline dangerous if you are writing to a version with a significant security issue (possible). On Ubuntu you would simply run a command similar to:

sudo aptitude install zendframework

If you are certain the latest version is available from your distribution's update server, only then consider it. At the time of writing this appears not to be the case though.

4.3.4. Nightly Build Download

I won't describe this further since it's currently not operable on the Zend Framework website. In the future however, this would allow you to grab the most recent nightly built version without going through Subversion.

4.4. Post Installation

That's about it for installing the Zend Framework. The only complex step is being aware the source code is packaged into four distinct parts, each of which would need to be separately added to the PHP include_path at some time. If you are comfortable with editing php.ini, you may do this immediately. If you do I suggest ordering included paths so that the Incubator paths are last. This ensures Incubator component classes do not take precedence over all others, but still allows access to any new original Incubator components. This ordering of include_paths also counts as a minor performance optimisation as described in this book's appendices.

Powered by jQuery Powered by Zend Framework Powered by Nginx Http Server