Setting up ZF2's Zend\Tool 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 Zend\Tool command line tool.

Rather unhelpfully, ZF2's Zend\Tool 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 Zend\Tool'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 Zend\Tool will run and not be affected by any ZF1 configurations you may have!

ZF1 and ZF2's cli scripts both work!

9 Responses to “Setting up ZF2's Zend\Tool side by side with ZF1”

  1. 1 Oleg Lobach

    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. 2 Rob...

    Hi Oleg,

    I actually have two copies of ZF2 on my computer... I've updated the article to be consistent :)

    Regards,

    Rob...

  3. 3 Oleg Lobach

    I thought that there is no difference of content of these two paths, but decided to clarify.

    Thanks for the explanation

  4. 4 Dev

    Anyway I can checkout latest ZF2 on Windows using Subversion?

    For Doctrine2 I can use:
    svn co http://svn.github.com/doctrine/doctrine2.git doctrine2-orm

    Tried:
    svn co http://git.zendframework.com/zf.git zf2

    But no cigar! Google also draws a blank.

    Thx

  5. 5 johan

    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 Zend\Tool\Project\Provider\Project in /Users/johan/zf2/library/Zend/Tool/Project/Provider/Project.php on line 241

  6. 6 sasquatch.mc

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

  7. 7 franck

    @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

  8. 8 Rob...

    I would tend to agree with sasquatch that ZF2's Zend\Tool is a work in progress...

  9. 9 sasquatch.mc

    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 Zend\Application\Application, Zend_Controller_Action with Zend\Controller\Action, Zend_Application_Bootstrap_Bootstrap with Zend\Application\Bootstrap. It worked for me.

The views expressed in these comments are not the views of the publisher. However, we believe in the rights of others to express their legitimate views and concerns. Any legitimate complaint emailed to rob@akrabat.com will be seriously considered and the post reviewed as desirable and necessary.