From 77a0cabe077870a32cc758150f405e255f794961 Mon Sep 17 00:00:00 2001 From: wa Date: Tue, 5 Jul 2016 23:44:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=B8=E5=AF=B9=E5=B9=B6=E7=BF=BB=E8=AF=91?= =?UTF-8?q?=E5=A5=BDstart-installation.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/guide-zh-CN/start-installation.md | 65 ++++++++++++-------------- 1 file changed, 31 insertions(+), 34 deletions(-) diff --git a/docs/guide-zh-CN/start-installation.md b/docs/guide-zh-CN/start-installation.md index e8f98b25b7..7bc256ba69 100644 --- a/docs/guide-zh-CN/start-installation.md +++ b/docs/guide-zh-CN/start-installation.md @@ -4,25 +4,20 @@ 你可以通过两种方式安装 Yii:使用 [Composer](http://getcomposer.org/) 或下载一个归档文件。 推荐使用前者,这样只需执行一条简单的命令就可以安装新的[扩展](structure-extensions.md)或更新 Yii 了。 -Standard installations of Yii result in both the framework and a project template being downloaded and installed. -A project template is a working Yii project implementing some basic features, such as login, contact form, etc. -Its code is organized in a recommended way. Therefore, it can serve as a good starting point for your projects. - -In this and the next few sections, we will describe how to install Yii with the so-called *Basic Project Template* and -how to implement new features on top of this template. Yii also provides another template called -the [Advanced Project Template](https://github.com/yiisoft/yii2-app-advanced/blob/master/docs/guide/README.md) which is better used in a team development environment -to develop applications with multiple tiers. +标准安装完Yii之后,框架和一个项目模板两者都下载并安装好了。 +一个项目模板是实现了一些基本特性的一个可行的Yii项目,比如登录,联系表单,等等。 +它的代码是以推荐的方式组织的。因此,它能够适合作为你项目的一个好的起点。 -> Info: The Basic Project Template is suitable for developing 90 percent of Web applications. It differs - from the Advanced Project Template mainly in how their code is organized. If you are new to Yii, we strongly - recommend you stick to the Basic Project Template for its simplicity yet sufficient functionalities. +在本章节和以后的章节,我们将会介绍如何去安装Yii和所谓的*基本的应用程序模板*和如何去实现这个模板上的新特性。Yii当然也提供了其它模板叫[高级的应用程序模板](https://github.com/yiisoft/yii2-app-advanced/blob/master/docs/guide/README.md),它是更好应用于在一个团队开发环境中去开发多层级的应用程序。 +> 信息:这个基本的应用程序模板是适合于开发90%的Web应用程序。 + 它不同于高级的应用程序模板主要地在如何使它们的代码是有组织的。如果你是刚接触Yii,我们强烈建议你坚持使用简单并有足够的功能的基础的应用程序模板。 通过 Composer 安装 ----------------------- 如果还没有安装 Composer,你可以按 [getcomposer.org](https://getcomposer.org/download/) 中的方法安装。 -在 Linux 和 Mac OS X 中可以运行如下命令: +在 Linux 和 Mac OS X 中,你可以运行如下命令: ```bash curl -sS https://getcomposer.org/installer | php @@ -40,19 +35,19 @@ mv composer.phar /usr/local/bin/composer Composer 安装后,切换到一个可通过 Web 访问的目录,执行如下命令即可安装 Yii : ```bash -composer global require "fxp/composer-asset-plugin:~1.1.1" +composer global require "fxp/composer-asset-plugin:^1.2.0" composer create-project --prefer-dist yiisoft/yii2-app-basic basic ``` 第一条命令安装 [Composer asset plugin](https://github.com/francoispluchino/composer-asset-plugin/), 它是通过 Composer 管理 bower 和 npm 包所必须的,此命令全局生效,一劳永逸。 -第二条命令会将 Yii 安装在名为 `basic` 的目录中,你也可以随便选择其他名称。 +第二条命令会将 Yii 安装在名为 `basic` 的目录中。如果你想使用其它目录名称,你可以选择其他目录名称。 -> Note: 在安装过程中 Composer 可能会询问你 GitHub 账户的登录信息,因为可能在使用中超过了 GitHub API (对匿名用户的)使用限制。因为 Composer 需要为所有扩展包从 GitHub +> 注意: 在安装过程中 Composer 可能会询问你 GitHub 账户的认证信息,因为可能在使用中超过了 GitHub API (对匿名用户的)使用限制。因为 Composer 需要为所有扩展包从 GitHub > 中获取大量信息,所以超限非常正常。(译注:也意味着作为程序猿没有 GitHub 账号,就真不能愉快地玩耍了)登陆 GitHub 之后可以得到更高的 API 限额,这样 Composer 才能正常运行。更多细节请参考 [Composer > 文档](https://getcomposer.org/doc/articles/troubleshooting.md#api-rate-limit-and-oauth-tokens)(该段 Composer中文文档[期待您的参与](https://github.com/5-say/composer-doc-cn/blob/master/cn-introduction/articles/troubleshooting.md#api-rate-limit-and-oauth-tokens))。 -> Tip: 如果你想安装 Yii 的最新开发版本,可以使用以下命令代替, +> 提示: 如果你想安装 Yii 的最新开发版本,可以使用以下命令代替, > 它添加了一个 [stability 选项](https://getcomposer.org/doc/04-schema.md#minimum-stability)([中文版](https://github.com/5-say/composer-doc-cn/blob/master/cn-introduction/04-schema.md#minimum-stability)): > > ```bash @@ -68,7 +63,7 @@ composer create-project --prefer-dist yiisoft/yii2-app-basic basic 通过归档文件安装 Yii 包括三个步骤: 1. 从 [yiiframework.com](http://www.yiiframework.com/download/) 下载归档文件。 -2. 将下载的文件解压缩到 Web 目录中。 +2. 将下载的文件解压缩到 Web 访问的文件夹中。 3. 修改 `config/web.php` 文件,给 `cookieValidationKey` 配置项 添加一个密钥(若你通过 Composer 安装,则此步骤会自动完成): @@ -83,29 +78,26 @@ composer create-project --prefer-dist yiisoft/yii2-app-basic basic 上文介绍了两种安装 Yii 的方法, 安装的同时也会创建一个立即可用的 Web 应用程序。 -对于小的项目或用于学习上手,这都是一个不错的起点。 +这个方法对大多数的大或者小的项目是一个不错的起点。如果你正好开始学习Yii,这是特别适合的。 但是其他的安装方式也存在: * 如果你只想安装核心框架,然后从零开始构建整个属于你自己的应用程序模版, 可以参考[从头构建自定义模版](tutorial-start-from-scratch.md)一节的介绍。 * 如果你要开发一个更复杂的应用,可以更好地适用于团队开发环境的, - 可以考虑安装[高级应用模版](tutorial-advanced-app.md)。 + 你可以考虑安装[高级应用模版](tutorial-advanced-app.md)。 验证安装的结果 -------------------------- -After installation is done, either configure your web server (see next section) or use the -[built-in PHP web server](https://secure.php.net/manual/en/features.commandline.webserver.php) by running the following -console command while in the project `web` directory: +当安装完成之后,或配置你的Web服务器(看下面的文章)或使用[内置Web Server](https://secure.php.net/manual/en/features.commandline.webserver.php),当在项目 `web` 目录下可以通过下面的命令: ```bash php yii serve ``` -> Note: By default the HTTP-server will listen to port 8080. However if that port is already in use or you wish to -serve multiple applications this way, you might want to specify what port to use. Just add the --port argument: +> 注意:默认情况下Https-server将监听8080。可是如果这个端口已经使用或者你想通过这个方式运行多个应用程序,你可以指定使用哪些端口。仅仅加上 --port 参数: ```bash php yii serve --port=8888 @@ -122,7 +114,7 @@ http://localhost:8080/ 你应该可以在浏览器中看到如上所示的 “Congratulations!” 页面。如果没有, 请通过以下任意一种方式,检查当前 PHP 环境是否满足 Yii 最基本需求: -* 通过浏览器访问 URL `http://localhost/basic/requirements.php` +* 复制 `/requirements.php` 到 `/web/requirements.php`,然后通过浏览器访问 URL `http://localhost/requirements.php` * 执行如下命令: ``` @@ -130,7 +122,7 @@ http://localhost:8080/ php requirements.php ``` -你需要配置好 PHP 安装环境,使其符合 Yii 的最小需求。主要是需要 PHP 5.4 以上版本。 +你需要配置好 PHP 安装环境,使其符合 Yii 的最小需求。主要是需要 PHP 5.4 或 以上版本。 如果应用需要用到数据库,那还要安装 [PDO PHP 扩展](http://www.php.net/manual/zh/pdo.installation.php) 和相应的数据库驱动(例如访问 MySQL 数据库所需的 `pdo_mysql`)。 @@ -138,7 +130,7 @@ http://localhost:8080/ 配置 Web 服务器 ----------------------- -> Info: 如果你现在只是要试用 Yii 而不是将其部署到生产环境中, +> 提示: 如果你现在只是要试用 Yii 而不是将其部署到生产环境中, 本小节可以跳过。 通过上述方法安装的应用程序在 Windows,Max OS X, @@ -149,15 +141,15 @@ Yii 2.0 也兼容 Facebook 公司的 [HHVM](http://hhvm.com/), 在生产环境的服务器上,你可能会想配置服务器让应用程序可以通过 URL `http://www.example.com/index.php` 访问而不是 `http://www.example.com/basic/web/index.php`。 -这种配置需要将 Web 服务器的文档根目录指向 `basic/web` 目录。 +这种配置需要将 Web 服务器的文档根目录(document root)指向 `basic/web` 目录。 可能你还会想隐藏掉 URL 中的 `index.php`,具体细节在 [URL 解析和生成](runtime-url-handling.md)一章中有介绍, 你将学到如何配置 Apache 或 Nginx 服务器实现这些目标。 -> Info: 将 `basic/web` 设置为文档根目录,可以防止终端用户访问 `basic/web` 相邻目录中 +> 信息: 将 `basic/web` 设置为文档根目录(document root),可以防止终端用户访问 `basic/web` 相邻目录中 的私有应用代码和敏感数据文件。 禁止对其他目录的访问是一个不错的安全改进。 -> Info: 如果你的应用程序将来要运行在共享虚拟主机环境中, +> 信息: 如果你的应用程序将来要运行在共享虚拟主机环境中, 没有修改其 Web 服务器配置的权限,你依然可以通过调整应用的结构来提升安全性。 详情请参考[共享主机环境](tutorial-shared-hosting.md) 一章。 @@ -168,7 +160,7 @@ URL `http://www.example.com/index.php` 访问而不是 `http://www.example.com/b 注意,你应该将 `path/to/basic/web` 替换为实际的 `basic/web` 目录。 ``` -# 设置文档根目录为 “basic/web” +# 设置文档根目录为 "basic/web" DocumentRoot "path/to/basic/web" @@ -188,7 +180,7 @@ DocumentRoot "path/to/basic/web" ### 推荐使用的 Nginx 配置 为了使用 [Nginx](http://wiki.nginx.org/),你应该已经将 PHP 安装为 [FPM SAPI](http://php.net/install.fpm) 了。 -使用如下 Nginx 配置,将 `path/to/basic/web` 替换为实际的 `basic/web` 目录, +你可以使用如下 Nginx 配置,将 `path/to/basic/web` 替换为实际的 `basic/web` 目录, `mysite.local` 替换为实际的主机名以提供服务。 ```nginx @@ -217,15 +209,20 @@ server { #} #error_page 404 /404.html; + # deny accessing php files for the /assets directory + location ~ ^/assets/.*\.php$ { + deny all; + } + location ~ \.php$ { include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; - fastcgi_pass 127.0.0.1:9000; + fastcgi_pass 127.0.0.1:9000; #fastcgi_pass unix:/var/run/php5-fpm.sock; try_files $uri =404; } - location ~ /\.(ht|svn|git) { + location ~* /\. { deny all; } }