Getting Started with the Yii Framework

REQUIREMENTS

實際需要使用到的:

文章中需要使用到:

INSTALL

在終端機上執行以下command:

1
2
sudo apt-get update
sudo apt-get install php5-cgi php5-fpm php5-sqlite php5-mysql nginx git

QUICK START

抓取yii的source:

1
git clone https://github.com/yiisoft/yii.git

建立一個webapp:

1
2
mkdir webapp
./yii/framework/yiic webapp webapp/

建立完後的目錄結構:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
.
├── assets
├── css
│   ├── bg.gif
│   ├── form.css
│   ├── ie.css
│   ├── main.css
│   ├── print.css
│   └── screen.css
├── images
├── index.php
├── index-test.php
├── protected
│   ├── commands
│   ├── components
│   ├── config
│   ├── controllers
│   ├── data
│   ├── extensions
│   ├── messages
│   ├── migrations
│   ├── models
│   ├── runtime
│   ├── tests
│   ├── vendor
│   ├── views
│   ├── yiic
│   ├── yiic.bat
│   └── yiic.php
└── themes
└── classic

其中assets、runtime和data,必須要讓www-data(nginx、apache)有讀、寫和執行的功能,可使用設定群組的方式,或者執行chmod -R 777 assets protected/runtime protected/data

打開nginx config:

1
sudo vi /etc/nginx/sites-enabled/default

修改以下這兩個location,設定你的webapp位置和設定fastcgi連接到php-fpm:

1
2
3
4
5
6
7
8
9
10
11
12
location / { 
root /tmp/webapp;
index index.html index.htm index.php;
}

location ~ \.php$ {
#fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /tmp/webapp$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}

如果使用的是nginx和php-fpm,請檢查php-fpm的listen設定,對應上面的fastcgi_pass。檔案位置在/etc/php5/fpm/pool.d/www.conf

設定完之後,重開nginx:

1
2
3
4
sudo /etc/init.d/nginx restart

#若是php-fpm的config的有被修改到,需重啟fpm
sudo /etc/init.d/php5-fpm restart

在瀏覽上打開http://localhost/,就可以看到剛剛佈署完的結果了。