Yii 是一個基於組件、高性能的 PHP 框架,專為大型 Web 應用開發設計。它採用嚴格的 OOP 模式,提供 MVC、DAO/ActiveRecord、緩存、RBAC、Web Service、國際化(I18N/L10N)等豐富功能,被公認為最高效的 PHP 框架之一。通過命令行工具 yiic 可快速生成應用骨架,讓開發者專注於業務邏輯。
/var/www/html/yii)。https://yourhost/path/to/yii/requirements/index.php。只要核心項目顯示 Passed 且結論為「滿足最低要求」即可。# 進入 framework 目錄
cd /var/www/html/yii/framework
# 生成應用骨架至 /var/www/html/testdrive
./yiic webapp ../../testdrive
生成的目錄結構包含入口腳本、配置文件、控制器、模型、視圖、運行時目錄等,開箱即用。
瀏覽器訪問 https://hostname/testdrive/index.php,即可看到包含首頁、聯系頁、登錄頁的默認應用。
# httpd.conf 中取消註釋
LoadModule rewrite_module modules/mod_rewrite.so
# 確保目錄允許覆蓋
AllowOverride All
'components' => array(
'urlManager' => array(
'urlFormat' => 'path',
'showScriptName' => false, // 關鍵:隱藏 index.php
'rules' => array(
'sites' => 'site/index',
),
),
),
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
server {
root /www/mysite/htdocs;
index index.php;
location / { try_files $uri $uri/ /index.php?$args; }
location ~ ^/(protected|framework|themes/\w+/views) { deny all; }
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
在 php.ini 中設置 cgi.fix_pathinfo=0 可提升安全性與性能。完成上述步驟,Yii 基礎環境即搭建完畢,可開始業務開發。