php 如何在 Windows 上安装 Zend 框架

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1857002/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 04:05:00  来源:igfitidea点击:

How to install Zend Framework on Windows

phpzend-framework

提问by Gal

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

“安装 Zend Framework 如此简单!!!” 对对...

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!"

“下载 Zend [...] 添加包含目录 (bla bla),您就大功告成了!”

right, i'm done using Zend.

对,我已经用完 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.

好吧,不是真的,反正还没有。我求求你们,我想睡觉了,请告诉我如何(简单的六年级细节)安装框架。我在 htdocs 目录中有解压后的文件夹,并将 zf.bat+zf.php 放在 htdocs 根目录中。

What's next?

下一步是什么?

thank you so much.

太感谢了。

采纳答案by Bill Karwin

It seems like you're having trouble with the PATHin the Windows command shell. This is independent of Zend Framework. Understanding the PATHconcept 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.

似乎您PATH在 Windows 命令外壳中遇到了问题。这独立于 Zend 框架。理解PATHshell 环境中的概念是许多程序员必须克服的障碍,但是一旦掌握了它,就可以使用它来提高生产力。

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 withoutnaming the full path to the executable, the shell tries to find the program executable in one of the directories listed in your PATHenvironment 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

但是,如果您在命令 shell 中运行命令而不命名可执行文件的完整路径,则 shell 会尝试在PATH环境变量中列出的目录之一中查找程序可执行文件。也就是说,路径是一个字符串,目录名用分号分隔。要运行可执行文件,shell 会按顺序尝试该列表中的每个目录,就好像您已经

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

Special case: running php.exealso 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.

特殊情况:php.exe如果您当前的工作目录恰好是该程序可执行文件的位置,则运行也有效。但这只是使用相对路径的一个示例,使用具有零目录级别的路径。

Second problem is that you're running zf.batwhich is a script that in turn invokes php.exewithout specifying a path. It assumes you have added the location of php.exeto your PATHenvironment variable.

第二个问题是您正在运行zf.bat它是一个脚本,该脚本在php.exe不指定路径的情况下调用。它假定您已将 的位置添加php.exePATH环境变量中。

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.batscript 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:

zf.bat脚本本身也需要被发现。您可以通过将它所在的目录添加到您的PATH. 假设您在 下安装了 Zend Framework C:\zf,例如:

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 outsideyour htdocsdirectory. 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.

我也建议您安装Zend框架之外htdocs目录。在您的htdocs:下只需要一个 PHP 文件:这是 Zend Framework 用于实例化 Front Controller 并分派请求的单个引导文件。

When you use zf.batto generate an skeleton application for you, it creates a directory publicwith a PHP script index.phpinside that directory. This index.phpfile is the one you need to be in your htdocsdirectory. 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 outsideyour htdocs. Especially any config files where you store sensitive data such as your database password, etc.

当您用来zf.bat为您生成框架应用程序时,它会在该目录中创建一个public带有 PHP 脚本的index.php目录。该index.php文件是您需要在htdocs目录中的文件。您还需要将 CSS、Javascript 和图像等资产放在htdocs. 您的应用程序代码的其余部分以及整个 Zend 框架本身应该您的htdocs. 尤其是存储敏感数据(例如数据库密码等)的任何配置文件。

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

您可以编辑index.php文件。它可以定义一个 PHP 常量APPLICATION_PATH,它是您应用程序代码其余部分的位置。

<?php

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

That default definition for APPLICATION_PATHassumes that your htdocsis a sister directory to the rest of your application code generated by the zf.battool. You can certainly put your app code anywhere else, but you have to change the above code so that the index.phpscript finds it.

的默认定义APPLICATION_PATH假定您htdocs是该zf.bat工具生成的其余应用程序代码的姊妹目录。您当然可以将您的应用程序代码放在其他任何地方,但您必须更改上面的代码,以便index.php脚本找到它。

Also the index.phpscript 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 librarysubdirectory to your PHP INCLUDE_PATH.

此外,index.php脚本可能会将库代码的位置添加到 PHP 的INCLUDE_PATH. 如果您需要使 Zend Framework 库可找到,或者如果您在应用程序中使用其他第三方 PHP 代码,这将非常有用。假设您在 下安装了 Zend Framework C:\zf,您应该将其library子目录添加到您的 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.batscript 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.

zf.bat脚本生成的代码模板尝试对代码所在的位置进行合理的默认猜测,但您的环境是您自己的,并且很容易编辑这些脚本以指定安装代码和库的真实位置。

回答by johannes

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

该框架不必在 htdocs 文件夹中,它可以在任何地方。一旦你把它解压到某个地方,你就完成了 50%。

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_dirdirective. This has to include the libraryfolder. Your setting might look like this:

下一步是找到你的 php.ini 文件(例如<?php phpinfo();?>在你的 htdocs 文件夹中创建一个文件执行它并在第一个块中查找“配置(php.ini)文件路径”(或类似的)。在该文件中添加路径到ZendFramework 到include_dir指令。这必须包括library文件夹。您的设置可能如下所示:

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

Often it also includes the path to PEAR.

通常它还包括 PEAR 的路径。

Then restart your server.

然后重启你的服务器。

You are done.

你完成了。

回答by markus

  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.
  1. Zend != Zend 框架
  2. Zend Framework 不需要安装。它只是一个图书馆,它只需要放置在某个地方。
  3. 正如约翰内斯所说,您需要告诉 php 在哪里查找库,以便将 Zend Framework 库所在的文件夹添加到您的 php 包含路径中。

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.

现在看来,您真正的问题与 Zend Framework 无关。您正在尝试使用 Zend_Tool,但命令行工具 zf.bat 不在您的系统路径中,因此您无法使用命令“zf”。Zend Framework 在没有该工具的情况下工作正常,如果您仍然想使用它,请在您位于 zf.bat 所在的文件夹中时调用该命令,或者将 zf.bat 的路径添加到您的系统路径中。

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';
}

回答by vikram raghuwanshi

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

源自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********

回答by Alex Angelico

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.
  1. 在任何地方解压框架
  2. 创建一个运行 zf create "myproject" 的项目
  3. /library => root folder of the framework. 您也可以将整个框架解压到此文件夹 (/library) 中,但是如果您有很多项目,则最终会使用磁盘空间获得许多框架副本。
  4. 在将 Web 浏览器重定向到您的站点时,更改用于打开 /myproject/public/index.php 的 apache 配置。

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.

我的意思是,这与 zf 无关,如果您在计算机上创建站点,您必须告诉 Apache 它在哪里。

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.

您始终可以运行 zf.bat 编写整个路径。如果 zf.bat 返回 un 错误,那么很可能你的 php 安装有问题。

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

以防万一它有帮助,这是我的名为 zf_cms 的项目的 apache 配置(httpd.conf)

<VirtualHost *:80>
ServerAdmin [email protected]
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

然后你必须将此行添加到 %windir%\system32\drivers\etc\hosts

127.0.0.1     zf_cms.conexion

回答by user226002

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.

当我发现在终端窗口中您需要首先导航到您创建的 PHP 主目录时,我解决了项目创建问题。

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

因此,换句话说,如果您在 PHP5 文件夹中,请键入“zf create project c:/Apache/htdocs/projectname”

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

我遇到了同样的问题:在我弄清楚之前,缺少 php.exe 文件。

--

——

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.

这是好消息。坏消息是,当您尝试设置控制器和操作时,您会遇到类似的问题,而我的修复程序对此不起作用。我仍然没有弄清楚这一点,所以我会再次发布更多信息,也许其他人可以提供帮助。

回答by user226002

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
  • 打开终端窗口
  • 键入 cd c:\
  • 键入 cd php
  • 键入 zf 创建项目 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.

那应该工作。请注意,您必须导航到 PHP 主目录,因为这是 php.exe 文件所在的位置,也是 zf.bat 和 zf.php 文件所在的位置。显然在使用 Zend_Tool 时两者都是必需的。

回答by Joe Internet

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.

您没有说明您使用的是什么网络堆栈,但我发现在 Windows 上使用 Zend 的最简单方法是安装Zend Core。这将安装一个预先配置有 Zend 框架的完整堆栈。