You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
159 lines
6.7 KiB
159 lines
6.7 KiB
12 years ago
|
Installation
|
||
|
============
|
||
|
|
||
11 years ago
|
There are two ways you can install the Yii framework:
|
||
|
|
||
11 years ago
|
* Via [Composer](http://getcomposer.org/) (recommended)
|
||
11 years ago
|
* By downloading an application template containing all of the site requirements, including the Yii framework itself
|
||
11 years ago
|
|
||
11 years ago
|
|
||
11 years ago
|
Installing via Composer
|
||
|
-----------------------
|
||
|
|
||
11 years ago
|
The recommended way to install Yii is to use the [Composer](http://getcomposer.org/) package manager. If you do not already
|
||
11 years ago
|
have Composer installed, you may download it from [http://getcomposer.org/](http://getcomposer.org/), or run the following command to download and install it:
|
||
11 years ago
|
|
||
|
```
|
||
|
curl -s http://getcomposer.org/installer | php
|
||
|
```
|
||
|
|
||
11 years ago
|
(It is strongly recommended to perform a [global Composer installation](https://getcomposer.org/doc/00-intro.md#globally)).
|
||
11 years ago
|
|
||
11 years ago
|
For problems with, or more information on, installing Composer, see the official Composer guide:
|
||
11 years ago
|
|
||
11 years ago
|
* [Linux](http://getcomposer.org/doc/00-intro.md#installation-nix)
|
||
11 years ago
|
* [Windows](http://getcomposer.org/doc/00-intro.md#installation-windows)
|
||
11 years ago
|
|
||
11 years ago
|
With Composer installed, you can create a new Yii site using one of Yii's ready-to-use application templates. Based on your needs, choosing the right template can help bootstrap your project.
|
||
11 years ago
|
|
||
11 years ago
|
Currently, there are two Yii application templates available:
|
||
11 years ago
|
|
||
11 years ago
|
- [Basic Application Template](https://github.com/yiisoft/yii2-app-basic), a basic frontend application template
|
||
|
- [Advanced Application Template](https://github.com/yiisoft/yii2-app-advanced), consisting of a frontend, a backend, console resources, common (shared code), and support for environments
|
||
11 years ago
|
|
||
11 years ago
|
For template installation instructions, see the above linked pages.
|
||
|
To read more about the ideas behind these application templates and the proposed usage,
|
||
11 years ago
|
refer to the [basic application template](apps-basic.md) and [advanced application template](apps-advanced.md) documents.
|
||
|
|
||
11 years ago
|
If you do not want to use a template, rather starting from scratch, you'll find information in the [creating your own application structure](apps-own.md) document. This approach is only recommended for advanced users.
|
||
11 years ago
|
|
||
11 years ago
|
|
||
|
Installing from zip
|
||
|
-------------------
|
||
|
|
||
11 years ago
|
Installation from a zip file involves two steps:
|
||
12 years ago
|
|
||
11 years ago
|
1. Downloading an application template from [yiiframework.com](http://www.yiiframework.com/download/).
|
||
11 years ago
|
2. Unpacking the downloaded file.
|
||
12 years ago
|
|
||
11 years ago
|
If you only want the Yii Framework files you can download a zip file directly from [github](https://github.com/yiisoft/yii2-framework/releases).
|
||
11 years ago
|
To create your application you might want to follow the steps described in [creating your own application structure](apps-own.md).
|
||
|
This is only recommended for advanced users.
|
||
|
|
||
11 years ago
|
> Tip: The Yii framework itself does not need to be installed under a web-accessible directory (in fact, it should not be).
|
||
|
A Yii application has one entry script, which is usually the only file that absolutely must be
|
||
11 years ago
|
exposed to web users (i.e., placed within the web directory). Other PHP scripts, including those
|
||
11 years ago
|
in the Yii Framework, should be protected from web access to prevent possible exploitation by hackers.
|
||
11 years ago
|
|
||
12 years ago
|
|
||
|
Requirements
|
||
|
------------
|
||
|
|
||
11 years ago
|
Yii 2 requires PHP 5.4.0 or higher. Yii has been tested with the [Apache HTTP server](http://httpd.apache.org/) and
|
||
|
[Nginx HTTP server](http://nginx.org/) on both Windows and Linux.
|
||
|
Yii may also be usable on other web servers and platforms, provided that PHP 5.4 or higher is present.
|
||
|
|
||
12 years ago
|
After installing Yii, you may want to verify that your server satisfies
|
||
11 years ago
|
Yii's requirements. You can do so by running the requirement checker
|
||
11 years ago
|
script in a web browser or from the command line.
|
||
|
|
||
11 years ago
|
If you have installed a Yii application template via the downloaded zip file or Composer, you'll find a `requirements.php` file in the
|
||
11 years ago
|
base directory of your application.
|
||
12 years ago
|
|
||
11 years ago
|
In order to run this script on the command line use the following command (after navigating to the directory where `requirements.php` can be found):
|
||
11 years ago
|
|
||
|
```
|
||
|
php requirements.php
|
||
|
```
|
||
|
|
||
11 years ago
|
In order to run this script in your browser, you must make sure it's within a web directory, and then
|
||
11 years ago
|
access `http://hostname/path/to/yii-app/requirements.php` in your browser.
|
||
11 years ago
|
|
||
12 years ago
|
|
||
|
Recommended Apache Configuration
|
||
|
--------------------------------
|
||
|
|
||
11 years ago
|
Yii is ready to work with a default Apache web server configuration. As a security measure, Yii comes with `.htaccess`
|
||
11 years ago
|
files in the Yii framework folder to deny access to the application's restricted resources.
|
||
11 years ago
|
|
||
11 years ago
|
By default, requests for pages in a Yii-based site go through the bootstrap file, usually named `index.php`, and placed
|
||
11 years ago
|
in the application's home directory. The result will be URLs in the format `http://hostname/index.php/controller/action/param/value`.
|
||
11 years ago
|
|
||
11 years ago
|
To hide the bootstrap file in your URLs, add `mod_rewrite` instructions to the `.htaccess` file in your web document root
|
||
11 years ago
|
(or add the instructions to the virtual host configuration in Apache's `httpd.conf` file, `Directory` section for your webroot).
|
||
|
The applicable instructions are:
|
||
12 years ago
|
|
||
|
~~~
|
||
|
RewriteEngine on
|
||
|
|
||
11 years ago
|
# If a directory or a file exists, use the request directly
|
||
12 years ago
|
RewriteCond %{REQUEST_FILENAME} !-f
|
||
|
RewriteCond %{REQUEST_FILENAME} !-d
|
||
11 years ago
|
# Otherwise forward the request to index.php
|
||
12 years ago
|
RewriteRule . index.php
|
||
|
~~~
|
||
|
|
||
11 years ago
|
|
||
12 years ago
|
Recommended Nginx Configuration
|
||
|
-------------------------------
|
||
|
|
||
11 years ago
|
Yii can also be used with the popular [Nginx](http://wiki.nginx.org/) web server, so long it has PHP installed as
|
||
|
an [FPM SAPI](http://php.net/install.fpm). Below is a sample host configuration for a Yii-based site on Nginx.
|
||
|
The configuration tells the server to send all requests for non-existent resources through the bootstrap file,
|
||
|
resulting in "prettier" URLs without the need for `index.php` references.
|
||
12 years ago
|
|
||
11 years ago
|
```
|
||
12 years ago
|
server {
|
||
11 years ago
|
set $yii_bootstrap "index.php";
|
||
12 years ago
|
charset utf-8;
|
||
11 years ago
|
client_max_body_size 128M;
|
||
12 years ago
|
|
||
11 years ago
|
listen 80; ## listen for ipv4
|
||
|
#listen [::]:80 default_server ipv6only=on; ## listen for ipv6
|
||
|
|
||
|
server_name mysite.local;
|
||
|
root /path/to/project/web;
|
||
|
index $yii_bootstrap;
|
||
12 years ago
|
|
||
11 years ago
|
access_log /path/to/project/log/access.log main;
|
||
11 years ago
|
error_log /path/to/project/log/error.log;
|
||
12 years ago
|
|
||
11 years ago
|
location / {
|
||
11 years ago
|
# Redirect everything that isn't real file to yii bootstrap file including arguments.
|
||
|
try_files $uri $uri/ /$yii_bootstrap?$args;
|
||
12 years ago
|
}
|
||
|
|
||
11 years ago
|
# uncomment to avoid processing of calls to unexisting static files by yii
|
||
|
#location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
|
||
|
# try_files $uri =404;
|
||
|
#}
|
||
|
#error_page 404 /404.html;
|
||
|
|
||
11 years ago
|
location ~ \.php$ {
|
||
|
include fastcgi.conf;
|
||
12 years ago
|
fastcgi_pass 127.0.0.1:9000;
|
||
11 years ago
|
#fastcgi_pass unix:/var/run/php5-fpm.sock;
|
||
12 years ago
|
}
|
||
|
|
||
11 years ago
|
location ~ /\.(ht|svn|git) {
|
||
|
deny all;
|
||
12 years ago
|
}
|
||
|
}
|
||
11 years ago
|
```
|
||
12 years ago
|
|
||
11 years ago
|
When using this configuration, you should set `cgi.fix_pathinfo=0` in the `php.ini` file in order to avoid many unnecessary system `stat()` calls.
|
||
11 years ago
|
|
||
|
|
||
11 years ago
|
Note that when running a HTTPS server you need to add `fastcgi_param HTTPS on;` in order for Yii to properly detect if
|
||
11 years ago
|
connection is secure.
|