How to install ZEND Framework for use with MAMP

ZEND_logoIf you have MAMP installed and working on your Mac, it’s easy to get started with ZEND Framework development. I’ll show you how in this article.

Download the framework from here:

Choose the full version without ZEND Server (not necessary as we’re using MAMP). Unpack the download and put it somewhere safe. I’m adding mine to my Documents directory. I’ll also rename my folder to something like “ZendFramework” without the version number.

To access it from anywhere on our machine we’ll create an alias named “zf”. zf is a shell script provided by the framework that we’ll need throughout our development journey with ZEND. Let’s to this in a Terminal session:

alias zf="/Users/you/Documents/ZendFramework/bin/'

Replace the path with your own. Notice the call to /bin/ which is the “real” shell script. Our alias has just made this universal and accessible without having to mess with our shell path.

Verify that it’s working with this:

zf show version

Zend Framework Version: 1.12.3

Tell PHP that we’re using the framework

Our final step is to patch the php.ini file of our Apache server. Since we’re using MAMP, there could be several PHP versions available and hence several accompanying ini files – so let’s make sure we patch the correct one.

Find your running MAMP window and click Preferences – PHP and check which version you’re running. ZEND requires PHP 5.3 or greater so make sure you do not choose 5.2. My current version is 5.5.3 but yours may be different:

Screen Shot 2014-02-15 at 18.56.20

All of MAMP’s php.ini files are located in /Applications/MAMP/conf, followed by your PHP version. Open it with TextEdit. About halfway down you’ll find the following section:

; Paths and Directories ;

; UNIX: "/path1:/path2"  
include_path = ".:/Applications/MAMP/bin/php/php5.5.3/lib/php"

We need to append our local path to the ZEND Framework for PHP to include it. Link to the library subdirectory. To stick with the above example, here’s what it should look like after the patch:

; Paths and Directories ;

; UNIX: "/path1:/path2"  
include_path = ".:/Applications/MAMP/bin/php/php5.5.3/lib/php:/Users/you/Documents/ZendFramework/library"

Now restart your MAMP servers and you should be good to go – in theory. Navigate to your app’s public directory and you should see the ZEND Default Page:

Screen Shot 2014-02-18 at 22.59.45


Copy ZEND Framework into your application directory

In theory PHP should now look for the ZEND Framework automatically, but this would mean that my app would only work on my own system. Sadly I only got a blank page, which tells me that PHP needs some glasses on my system ;-) But even if it had worked, it may stop working as soon as I try to host my files on a system without the framework and the PHP patch.

Therefore it’s a good idea to include a copy of ZEND Framework along with my own files (which made the above default page come up as it should have – so it solved a problem on my local system too).

It’s easy to do: copy the contents of your local ZendFramework/library folder into your application’s /library folder. There should only be a single subfolder to copy (called Zend), about 30MB in size.

With that done your app should run on any PHP 5.4+ capable web server out of the box, no PHP tweaks required.

Happy hacking!

You can leave a comment on my original post.