开发者

How to install Zend Framework on Windows

"installing Zend Framework is so easy!!!!" yeah right...

Ok I'm working with a beginner's book and the ONE thing that is not excessively detailed is the most important part开发者_如何学编程: Installing the darn thing. After browsing the quickstart guide for hours, all it said was:

"download Zend [...] add the include directory (bla bla) and YOU'RE DONE!"

right, i'm done using Zend.

Ok, not really, not yet anyway. I beg of you people, I wanna go to bed, please tell me how (in simple 6th grade detail) to install the framework. I've got the unzipped folder in my htdocs directory, and I placed zf.bat+zf.php in the htdocs root.

What's next?

thank you so much.


It seems like you're having trouble with the PATH in the Windows command shell. This is independent of Zend Framework. Understanding the PATH concept in a shell environment is a hurdle many programmers have to overcome, but once you get it, you can use it to increase your productivity.

You can always run a program from the command shell using that program's absolute path. For example:

C:\> c:\wamp\bin\php\php.exe

You can also run a command using a relative path. That is, you enter the path from your current working directory to the location of the program you want to run.

C:\> cd c:\wamp
C:\> bin\php\php.exe

But if you run a command in the command shell without naming the full path to the executable, the shell tries to find the program executable in one of the directories listed in your PATH environment variable. That is, the path is a string with directory names separated by semicolons. To run an executable, the shell tries each directory in that list, in order, as if you had

C:\> type %PATH%
C:\WINDOWS\;C:\WINDOWS\SYSTEM32
C:\> php.exe
...error that it cannot find php.exe...

Special case: running php.exe also works if your current working directory happens to be the location of that program executable. But that's just an example of using a relative path, using a path with zero directory levels.

Second problem is that you're running zf.bat which is a script that in turn invokes php.exe without specifying a path. It assumes you have added the location of php.exe to your PATH environment variable.

C:\> SET PATH=%PATH%;C:\wamp\bin\php
C:\> php.exe -v
PHP 5.3.1 (cli) (built: Nov 29 2009 13:59:20) 
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2009 Zend Technologies

The zf.bat script itself also needs to be found. You can do this by adding the directory where it resides to your PATH. Assuming you installed Zend Framework under C:\zf, for example:

C:\> type %PATH%
C:\WINDOWS\;C:\WINDOWS\SYSTEM32;C:\wamp\bin\php
C:\> zf.bat
...error that it cannot find zf.bat...
C:\> SET PATH=%PATH%;C:\zf\bin
C:\> zf.bat show version
Zend Framework Version: 1.10.0dev

I would also recommend that you install Zend Framework outside your htdocs directory. There's only one PHP file you need under your htdocs: that is the single bootstrap file that Zend Framework uses to instantiate the Front Controller and dispatch the request.

When you use zf.bat to generate an skeleton application for you, it creates a directory public with a PHP script index.php inside that directory. This index.php file is the one you need to be in your htdocs directory. You also need assets like CSS, Javascript, and images to be under your htdocs. The rest of your application code, and the entire Zend Framework itself, should be outside your htdocs. Especially any config files where you store sensitive data such as your database password, etc.

You can edit the index.php file. It may define a PHP constant APPLICATION_PATH, which is the location of the rest of your application code.

<?php

defined("APPLICATION_PATH")
    || define("APPLICATION_PATH", realpath(dirname(__FILE__) . "/../application"
));

That default definition for APPLICATION_PATH assumes that your htdocs is a sister directory to the rest of your application code generated by the zf.bat tool. You can certainly put your app code anywhere else, but you have to change the above code so that the index.php script finds it.

Also the index.php script may add the location of library code to PHP's INCLUDE_PATH. This is useful if you need to make the Zend Framework library findable, or if you use other third-party PHP code in your application. Assuming you installed Zend Framework under C:\zf, you should add its library subdirectory to your PHP INCLUDE_PATH.

// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
    "C:/zf/library",
    realpath(APPLICATION_PATH . "/../library"),
    get_include_path()
)));

The code templates generated by the zf.bat script try to make sensible default guesses about where your code is located, but your environment is your own, and it's easy to edit these scripts to specify the true location where you installed your code and libraries.


The framework doesn't have to be in the htdocs folder, it can be anywhere. Once you decompressed it somewhere you're 50% done.

Next step is to locate your php.ini file (for instance create a file <?php phpinfo();?> in your htdocs folder execute it and look for "Configuration (php.ini) filepath" (or similar) in the first block. In that file add the path to the ZendFramework to the include_dir directive. This has to include the library folder. Your setting might look like this:

include_dir = .;c:\php\ZendFramework\library

Often it also includes the path to PEAR.

Then restart your server.

You are done.


  1. Zend != Zend Framework
  2. Zend Framework doesn't need to be installed. It is merely a library, it just needs to be placed somewhere.
  3. As johannes says you need to tell php where to look for the library so you add the folder where the Zend Framework library is located to your php include path.

That's it, there is nothing more!

Now it seems that your real problem has nothing to do with Zend Framework as such. You're trying to use Zend_Tool but the command line tool zf.bat is not on your system path so you are not able to use the command 'zf'. Zend Framework works fine without the tool, if you want to use it anyways, invoke the command, when you're in the folder where zf.bat resides or add the path to zf.bat to your system path.

This means in a non-vague way:

if (path-to-zf.bat isOn SYSTEM_PATH)
{
    you can call 'zf' from anywhere;
}
else
{
    you must be in the folder where zf.bat also is, if you want to call 'zf';
}


Derived from http://normankosmal.com/wordpress/?p=47:

****> ****Process  of install zend framework in window 
> 1) Download zend framework
> 2)After installing xampp extract the
> Zend Framework files into a folder of
> your choice. Next step is to edit the
> php.ini. Usually this file can be
> found in the php folder in your xampp
> installation. Find the line that says
> include_path and edit the line like
> this:
>     Windows: “\path1;\path2″
>     include_path = “.;D:\Informatik\SERVER\xampp\php\pear\;D:\Informatik\SERVER\xampp\php\ZendFramework\library”
>     3) 
>      did you add your php interpreter to %PATH%?
>     In which file i have to add the PHP interpreter?
>     You mean i need to edit zf.bat file
>     SET ZF_SCRIPT=%PHP_DIR%\zf.php
>     Here in place of %PHP_DIR% i need to add the path of my PHP directory?
>     Can you plzz help me out.
>     4) D:\Informatik\SERVER\xampp\htdocs>D:\Informatik\SERVER\xampp\php\ZendFramework\b
>     in\zf.bat create project testproject********


Gal - I had the same problem. We must be working on the same book this weekend.

I solved the project-creation problem when I figured out that in the terminal window, you need to first navigate to the PHP home directory you created.

So in other words if you are in the PHP5 folder, type "zf create project c:/Apache/htdocs/projectname"

I had the same issue re: missing php.exe file until I figured this out.

--

That's the good news. The bad news is you're going to have similar problems when you try setting up Controllers and Actions, and my fix won't work for this. I still haven't figured this out, so I'll post again with more info and perhaps the others can help.


Easier to read if I type it here.

Here's a step-by-step:

  • open terminal window
  • type cd c:\
  • type cd php
  • type zf create project c:/APACHE/htdocs/PROJECTNAME

Substitute your directory and project names where I used all caps.

That should work. Notice that you had to navigate to the PHP home directory because this is where the php.exe file is, and this is where the zf.bat and zf.php files are. Apparently both are required when using Zend_Tool.


You don't say what web stack you're using, but the simplest way that I've found to work with Zend on Windows is to install Zend Core. This installs a complete stack pre-configured with the Zend Framework.


Gal, I don't understand what do you want to do.

There is no installation or configuration for the framework. You just have to

  1. Unpack the framework anywhere
  2. Create a project running zf create "myproject"
  3. Create a shourtcut/link in /library => root folder of the framework. You can also just unpack the whole framework in this folder (/library) but if you have many projects, you will end with many copies of the framework using diskspace.
  4. change you apache configuration for opening /myproject/public/index.php when redirecting the web browser to your site.

I mean, this have nothing to do with zf, if you create a site in your computer, you have to tell Apache where is it.

You always can run zf.bat writing the whole path. If zf.bat returns un error, then very probably you have problems with you php installation.

Just in case it's helpful, this is my apache configuration (httpd.conf) for a project named zf_cms

<VirtualHost *:80>
ServerAdmin alex@conexion-seo.com.mx
DocumentRoot "C:\Users\alex\Documents\My Web Sites\zf_cms/public"
ServerName zf_cms.conexion

<Directory "C:\Users\alex\Documents\My Web Sites\zf_cms/public">
    #DirectoryIndex index.php
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

Then you have to add this line to %windir%\system32\drivers\etc\hosts

127.0.0.1     zf_cms.conexion
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜