1、下载Yii并解压
地址:http://www.yiiframework.com/download/
2、拿出framework文件夹,放在服务器的webroot目录下,打开命令行,导航到webroot执行一下命令创建一个应用
1 % YiiRoot/framework/yiic webapp WebRoot/testdrive
yiic是脚本文件,webapp表示生成网站应用,后面就是网站放置的路径了
3、然后开始配置虚拟主机
gvim /etc/apache2/sites-enabled/000-default
4、添加一个虚拟主机,添加一下代码,这是用域名配置虚拟主机
1 <VirtualHost *:80> 2 DocumentRoot /home/linksgo2011/www/pay 3 ServerName pay.dev 4 <Directory /> 5 Options Indexes FollowSymLinks MultiViews 6 AllowOverride all 7 Order allow,deny 8 allow from all 9 </Directory> 10 11 <Directory /home/linksgo2011/www/pay > 12 Options Indexes FollowSymLinks MultiViews 13 AllowOverride all 14 Order allow,deny 15 allow from all 16 </Directory> 17 # Other directives here 18 </VirtualHost>
3、重启apache
etc/init.d/apache2 restart
4、修改host文件
#gvim /etc/hosts #添加一行 127.0.0.1 pay.dev
5、配置Yii
//配置gii 'gii'=>array( 'class'=>'system.gii.GiiModule', 'password'=>'Enter Your Password Here', // If removed, Gii defaults to localhost only. Edit carefully to taste. 'ipFilters'=>array('127.0.0.1','::1'), ), //配置urlrewirte 'urlManager'=>array( 'urlFormat'=>'path', 'showScriptName' => false, //是否显示index.php入口文件名 'rules'=>array( '<controller:\w+>/<id:\d+>'=>'<controller>/view', '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>', '<controller:\w+>/<action:\w+>'=>'<controller>/<action>', ), ), //配置数据库 'db'=>array( 'connectionString' => 'mysql:host=localhost;dbname=pay', 'emulatePrepare' => true, 'username' => 'root', 'password' => '', 'charset' => 'utf8', ), //配置日志 'log'=>array( 'class'=>'CLogRouter', 'routes'=>array( array( 'class'=>'CFileLogRoute', 'levels'=>'error, warning', ), // uncomment the following to show log messages on web pages array( 'class'=>'CWebLogRoute', ), ), ),
6、添加rewrite规则文件(关键)
#保存为.htaccess文件 <IfModule rewrite_module> Options +FollowSymLinks IndexIgnore */* RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . index.php </IfModule>
把.htaccess文件放到应用的目录下即可