Pragmatism in the real world

Setting up ZF2's ZendTool side by side with ZF1

Note: this article does not refer to the released version of Zend Framework 2!.

If you want to play with the development versions of Zend Framework 2.0, then it’s handy to be able to create ZF2 projects using the ZendTool command line tool.

Rather unhelpfully, ZF2’s ZendTool uses the same ini file (~/.zf.ini) as ZF1’s Zend_Tool and the same zf.sh script filename, so you can’t just put zf2 on to your path and it’ll all just work.

I am assuming that you’re like me and have production sites using ZF1, so you probably don’t want to mess up your current zf.sh usage. This is how I implemented side-by-side ZF cli scripts.

1. Install ZF2 somewhere

I like to install in /usr/local/include. From the command line type:

cd /usr/local/include
git clone git://git.zendframework.com/zf.git zf2

Don’t forget to periodically update it with:

cd /usr/local/include
git pull origin master

(And don’t be surprised when it breaks whatever you’ve already coded in ZF2.dev!)

2. Create .zf2.ini

You need an ini file for ZF2, so call it .zf2.ini and store it in your home directory next to .zf.ini. You need to set the correct include path so that ZendTool’s zf.php can find your ZF2 installation. From the command line type:

echo 'php.include_path = "/usr/local/include/zf2/library:/usr/local/include/Akrabat/zf2/"' >> ~/.zf2.ini

This creates the .zf2.ini file with the correct include_path set up.

3. Create a zf2 alias

Update your ~/.bash_profile to set up an alias to the ZF2 zf.sh script.

Using a text edit, add this line to the end of ~/.bash_profile:

alias zf2='export ZF_CONFIG_FILE=~/.zf2.ini; /usr/local/include/zf2/bin/zf.sh'

Restart your terminal or type source ~/.bash_profile

Now you can type zf2 to run ZF2’s zf.sh and ZendTool will run and not be affected by any ZF1 configurations you may have!

ZF1 and ZF2's cli scripts both work!

9 thoughts on “Setting up ZF2's ZendTool side by side with ZF1

  1. Hi Rob

    Very useful post, thanks.

    But why are different paths to ZF2 at the second and third step?
    '/www/zend-framework/zf2/bin/' – this is a symlink to '/usr/local/include/zf2/'?

  2. Hi Rob,

    I set this op in my home folder, but when I try to use the zf2 command, eg. zf2 create project zf2test i get the following error:
    Fatal error: Cannot redeclare class ZendToolProjectProviderProject in /Users/johan/zf2/library/Zend/Tool/Project/Provider/Project.php on line 241

  3. @johan I have the same problem. It's look like that ZendTool ain't ready for use yet

  4. @johan @sasquatch
    I had the same problem. But I downloaded today the last version by Git, and there is still a problem, but different :

    When I now run "zf2 create project foo", I have a zf.sh error :

    An Error Has Occurred
    "projectDirectory" was supplied but no profile file file was not found
    at location /.zfproject.xml

  5. I've tried with zf.sh v1 to create the project, and just replaced the old classes with the new, with namespaces – Zend_Application with ZendApplicationApplication, Zend_Controller_Action with ZendControllerAction, Zend_Application_Bootstrap_Bootstrap with ZendApplicationBootstrap. It worked for me.

Comments are closed.