YII安装时的简单配置 [ 1.0 版本 ]
一、虚拟机
(1)虚拟主机+.htaccess文件(推荐)
配置apache虚拟主机(/etc/httpd/conf.d/vhost.conf)
<VirtualHost *:80>
ServerAdmin myYii.com
DocumentRoot "/www/test/advanced/frontend/web"
ServerName myYii.com
ErrorLog "logs/myYii.com-error_log"
CustomLog "logs/myYii.com-access_log" common
<Directory /www/test/advanced/frontend/web>
AllowOverride All
Options FollowSymLinks
</Directory>
</VirtualHost>
在web目录下添加.hatccess文件
RewriteEngineon
# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule . index.php
(2)虚拟主机
<VirtualHost *:80>
ServerAdmin basic.com
DocumentRoot "/web_data/basic/web"
ServerName basic.com
ErrorLog "logs/basic.com-error_log"
CustomLog "logs/basic.com-access_log" common
<Directory /web_data/basic/web>
AllowOverride All
Options FollowSymLinks
RewriteEngine on
# 如果请求的是真实存在的文件或目录,直接访问
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# 如果请求的不是真实文件或目录,分发请求至 index.php
RewriteRule . index.php
</Directory>
</VirtualHost>
二、debug工具gii工具
if (YII_ENV_DEV) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = [
'class' => 'yii\debug\Module',
'allowedIPs' => ['192.168.*']
];
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
'class'=>'yii\gii\Module',
'allowedIPs'=>['192.168.*'],
];
}
注:debug工具要在入口文件中开启defined('YII_DEBUG')
or define('YII_DEBUG', true);
注:gii工具需要下载 php composer.phar require --prefer-dist yiisoft/yii2-gii "*"
或者
composer.json
中加入 "yiisoft/yii2-gii": "*"
三、简单URL优化
'components' => [
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
],
],
四、配置数据库
return [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=yii',
'username' => 'root',
'password' => '123456',
'charset' => 'utf8',
];
specialnot
注册时间:2015-08-06
最后登录:2019-08-16
在线时长:27小时54分
最后登录:2019-08-16
在线时长:27小时54分
- 粉丝43
- 金钱1175
- 威望200
- 积分3445
共 1 条评论
很好很好!