您的位置:首页 > 编程语言 > PHP开发

【ZF2】ZendFramework-2.1.4 安装实例(win7)

2014-11-13 10:29 127 查看
本方法基于:ZendFramework 2.1.4版本在WIN7下构建,其他版本的安装方式相差不大。

操作之前您需要搭建好PHP运行环境,保证PHP版本不低于PHP 5.3.3,并且去http://framework.zend.com/downloads/latest下载好ZF2的library。


方式一.最简单方便的安装方式

直接去https://github.com/zendframework/ZendSkeletonApplication下载项目文件,然后把下载的ZF2中的library所有文件直接拷贝到vendor/ZF2目录中(目录格式为vendor\ZF2\library\Zend\)。


方式二. 官方推荐安装方式

1. 下载ZendFramework-2.1.4,提取其中的zend目录。

2. 在php.ini中添加 include_path = “.;c:\你的目录\Zend”。

(此处 建立虚拟目录啊、改HOSTS文件什么的都不详解了)

3. 此时可以去https://github.com/zendframework/ZendSkeletonApplication下载使用了,但是直接访问的时候的时间提示
Fatal error: Uncaught exception 'RuntimeException' with message 'Unable to load ZF2. Run `php composer.phar install` or define a ZF2_PATH environment variable.' in...


4. 我们直接采用设置ZF2_PATH环境的方法。找到http.conf 文件 添加SetEnv ZF2_PATH “C:/<你的ZF2框架目录>”(注意这里不需要添加路径zend)。



方式三. 在线安装

1. 直接去https://github.com/zendframework/ZendSkeletonApplication下载运行。

2. 这时候我们选择php composer.phar install 的方式来安装,用CMD进入到composer.phar所在目录执行 php composer.phar install ,这时候可能会出现两种错误

一种是:
'php' 不是内部或外部命令,也不是可运行的程序或批处理文件。


很显然是没有找到PHP环境,这时候自己去配置好环境就行(怎么配置PHP环境变量?打开“我的电脑”->“属性”->“高级”->“环境变量”->“系统变量”->“path”,编辑其值,添加你的PHP所有路径就行了),要是觉得麻烦我试了下把整个PHP的运行文件复制到目录下也能行(当然不推荐这样,太乱了)。

另一种是:
This dev build of composer is outdated, please run "composer.phar self-update" t
o get the latest version.
Loading composer repositories with package information
Installing dependencies
- Installing zendframework/zendframework (2.1.4)

[RuntimeException]
You must enable the openssl extension to download files via https

install [--prefer-source] [--dry-run] [--dev] [--no-custom-installers] [--no-scr
ipts] [-v|--verbose]


此时只需要开启php.ini中的extension=php_openssl.dll就行了

3 .要是出现
This dev build of composer is outdated, please run "composer.phar self-update" t
o get the latest version.
Loading composer repositories with package information
Installing dependencies
- Installing zendframework/zendframework (2.1.4)
Downloading: 100%

zendframework/zendframework suggests installing doctrine/common (Doctrine\Common
>=2.1 for annotation features)
zendframework/zendframework suggests installing ext-intl (ext/intl for i18n feat
ures)
zendframework/zendframework suggests installing ircmaxell/random-lib (Fallback r
andom byte generator for Zend\Math\Rand if OpenSSL/Mcrypt extensions are unavail
able)
zendframework/zendframework suggests installing pecl-weakref (Implementation of
weak references for Zend\Stdlib\CallbackHandler)
zendframework/zendframework suggests installing zendframework/zendpdf (ZendPdf f
or creating PDF representations of barcodes)
zendframework/zendframework suggests installing zendframework/zendservice-recapt
cha (ZendService\ReCaptcha for rendering ReCaptchas in Zend\Captcha and/or Zend\
Form)
Writing lock file
Generating autoload files


就说明已经安装成功了,此中方法不需要添加php include_path ,也不需要向添加ZF2_PATH环境。

至此PHP的安装算是基本上完成了

下面讲进行一些相关的配置:

1. 配置apache

1.1开启URL重写功能

1.2 配置虚拟目录
<VirtualHost *:80>
ServerName zf2.localhost
DocumentRoot zf2项目路径/public
SetEnv APPLICATION_ENV "development"
<Directory zf2项目路径/public>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>


1.3 将域名zf2.localhost指向本机,在hosts文件(路径:c:\windows\system32\drivers\etc\hosts)中添加
127.0.0.1 zf2.localhost


此时通过域名zf2.localhost就可以直接访问到你的项目了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: