installation.md 3.73 KB
Newer Older
Qiang Xue committed
1 2 3
Installation
============

4 5 6
Installing via Composer
-----------------------

7 8 9 10 11 12 13 14 15
The recommended way of installing Yii is by using [Composer](http://getcomposer.org/) package manager. If you do not
have it, you may download it from [http://getcomposer.org/](http://getcomposer.org/) or run the following command:

```
curl -s http://getcomposer.org/installer | php
```

Yii provides a few ready-to-use application templates. Based on your needs, you may choose one of them to bootstrap
your project.
16 17 18 19 20 21 22

There are two application templates available:

- [basic](https://github.com/yiisoft/yii2-app-basic) that is just a basic frontend application template.
- [advanced](https://github.com/yiisoft/yii2-app-advanced) that is a set of frontend, backend, console, common
 (shared code) and environments support.

23 24
Please refer to installation instructions on these pages. To read more about ideas behing these application templates and
proposed usage refer to [basic application template](apps-basic.md) and [advanced application template](apps-advanced.md).
25 26 27 28 29

Installing from zip
-------------------

Installation from zip mainly involves the following two steps:
Qiang Xue committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50

   1. Download Yii Framework from [yiiframework.com](http://www.yiiframework.com/).
   2. Unpack the Yii release file to a Web-accessible directory.

> Tip: Yii does not need to be installed under a Web-accessible directory.
A Yii application has one entry script which is usually the only file that
needs to be exposed to Web users. Other PHP scripts, including those from
Yii, should be protected from Web access; otherwise they might be exploited
by hackers.

Requirements
------------

After installing Yii, you may want to verify that your server satisfies
Yii's requirements. You can do so by accessing the requirement checker
script via the following URL in a Web browser:

~~~
http://hostname/path/to/yii/requirements/index.php
~~~

51
Yii requires PHP 5.4.0, so the server must have PHP 5.4.0 or above installed and
Alexander Makarov committed
52 53
available to the web server. Yii has been tested with [Apache HTTP server](http://httpd.apache.org/)
on Windows and Linux. It may also run on other Web servers and platforms,
54
provided PHP 5.4 is supported.
Qiang Xue committed
55 56 57 58 59 60


Recommended Apache Configuration
--------------------------------

Yii is ready to work with a default Apache web server configuration.
Alexander Makarov committed
61
The `.htaccess` files in Yii framework and application folders deny
Qiang Xue committed
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
access to the restricted resources. To hide the bootstrap file (usually `index.php`)
in your URLs you can add `mod_rewrite` instructions to the `.htaccess` file
in your document root or to the virtual host configuration:

~~~
RewriteEngine on

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
~~~


Recommended Nginx Configuration
-------------------------------

You can use Yii with [Nginx](http://wiki.nginx.org/) and PHP with [FPM SAPI](http://php.net/install.fpm).
Here is a sample host configuration. It defines the bootstrap file and makes
Yii to catch all requests to nonexistent files, which allows us to have nice-looking URLs.

~~~
server {
    charset utf-8;

88 89 90
    listen       80;
    server_name  mysite.local;
    root         /path/to/project/webroot/directory
Qiang Xue committed
91

92
    access_log  /path/to/project/log/access.log  main;
Qiang Xue committed
93

94 95
    location / {
        try_files   $uri $uri/ /index.php?$args; # Redirect everything that isn't real file to index.php including arguments.
Qiang Xue committed
96 97
    }

98 99
    location ~ \.php$ {
        include fastcgi.conf;
Qiang Xue committed
100
        fastcgi_pass   127.0.0.1:9000;
lancecoder committed
101
        #fastcgi_pass unix:/var/run/php5-fpm.sock;
Qiang Xue committed
102 103
    }

104 105
    location ~ /\.(ht|svn|git) {
        deny all;
Qiang Xue committed
106 107 108 109
    }
}
~~~

110
Make sure to set `cgi.fix_pathinfo=0` in php.ini to avoid many unnecessary system `stat()` calls.